KScript docs
EN

page_visit fields and methods

A field is a plain fact about the value, read with a dot and no brackets: $value.name. A method takes arguments or does work, and is called with ->: $value->name(arguments), or with the value piped in: $value |> name(arguments).

Fields

FieldTypeDescription
.htmlstringThe page's HTML as it is now, after any clicks.
.pathstringThe address visited.
.statusnumberThe HTTP status of the last render.
.textstringThe words on the page as it is now, without tags and with runs of spaces made one.

From KScript.Web

These need <import package="KScript.Web" />import KScript.Web. See KScript.Web.

#page_visit->change(text: string) → page_visit KScript.Web

Runs the on-change handler of the input with this label (the text of the <label> around it), such as a checkbox, and redraws its block.
ParameterTakes
text requiredstring
Example
<let name="page" value="@visit('/settings')->change('Email me updates')" />
<expect value="$page.text" contains="'Saved'" />
$page = @visit('/settings')->change('Email me updates')
expect($page.text, contains: 'Saved')

#page_visit->classes(text: string) → list KScript.Web

The classes of the first element whose own text is this: classes('Buy milk').
ParameterTakes
text requiredstring
Example
<let name="page" value="@visit('/tasks')->click('Buy milk')" />
<expect value="$page->classes('Buy milk')" contains="'done'" />
$page = @visit('/tasks')->click('Buy milk')
expect($page->classes('Buy milk'), contains: 'done')

#page_visit->click(text: string) → page_visit KScript.Web

Runs the live on-click handler of the element with this text (or aria-label or title) and redraws its block. Returns the page, so clicks chain.
ParameterTakes
text requiredstring
Example
<let name="page" value="@visit('/counter')->click('Add one')->click('Add one')" />
<expect value="$page.text" contains="'2'" />
$page = @visit('/counter')->click('Add one')->click('Add one')
expect($page.text, contains: '2')

#page_visit->fill(field: string, value) → page_visit KScript.Web

Types a value into the input bound to this field (bind="$draft"), sent with the next click or submit.
ParameterTakes
field requiredstring
value requiredany value

Arguments can be named: ->fill(…, value: …).

Example
<let name="page" value="@visit('/tasks')->fill('draft', 'Buy milk')->click('Add')" />
<expect value="$page.text" contains="'Buy milk'" />
$page = @visit('/tasks')->fill('draft', 'Buy milk')->click('Add')
expect($page.text, contains: 'Buy milk')

#page_visit->press(key, in?: string) → page_visit KScript.Web

Presses a key on the element with on-keydown (the one with this text, label or placeholder, when given in:): press('enter'), press(['ctrl', 's']).
ParameterTakes
key requiredany value
in optionalstring

Arguments can be named: ->press(…, in: …).

Example
<let name="page" value="@visit('/tasks')->fill('draft', 'Buy milk')->press('enter', in: 'New task')" />
<expect value="$page.text" contains="'Buy milk'" />
$page = @visit('/tasks')->fill('draft', 'Buy milk')->press('enter', in: 'New task')
expect($page.text, contains: 'Buy milk')

#page_visit->submit(text?: string) → page_visit KScript.Web

Runs the on-submit handler of the form (the one with this text, when given) and redraws its block.
ParameterTakes
text optionalstring
Example
<let name="page" value="@visit('/signup')->fill('email', 'joan@example.com')->submit('Sign up')" />
<expect value="$page.text" contains="'Check your email'" />
$page = @visit('/signup')->fill('email', 'joan@example.com')->submit('Sign up')
expect($page.text, contains: 'Check your email')

Methods from any