Skip to main content

Text capture

I capture <textRef> as <name>

Captures the referenced text and binds it to the given name in the global scope.

Where

  • <textRef> is the name of the binding containing the source text

    • Can be the name of any binding that contains or resolves to a text value, including a web element in which case the text in the element will be dynamically retrieved and used.
  • <name> is the name to bind the captured value to

Example

  Given the username is "Gwen"
When I capture the username as my username
Then my username should be the username
I capture <element>

Captures the text value of an element and binds it to the element name in the global scode.

Where

  • <element> is the name of the element to capture the text of

Example

  Given the heading can be located by tag "h1"
When I navigate to "https://todomvc.com/examples/react/dist"
And I capture the heading
I capture <element> as <name>

Captures the text value of an element and binds it to the given name in the global scope.

Where

  • <element> is the name of the element to capture the text of
  • <name> is the name to bind the captured text to

Example

  Given the heading can be located by tag "h1"
When I navigate to "https://todomvc.com/examples/react/dist"
And I capture the heading as my heading
I capture <name> <of|on|in> <element> by <javascript|js> "<script>"

Executes a JavaScript expression or function on an element and binds the result to the given name.

Where

  • <name> is the name to bind the javascript return value to
  • <of|on|in> is of, on or in
  • <element> is the name of the element to execute the javascript on
  • <javascript|js> is javascript (or js, since v2.46.0)
  • <script> is the javascript expression or function that will return the value (can be in DocString position)

    • The reference to the element will be provided to the javascript through an implicit object named element.
    • For a one liner expression, no function, arrow declaration or return prefix is required
    • For a function, use either:

      • Arrow syntax (preferred): () => { body } (Since v3.56.0)
      • Or anonymous function syntax (legacy): (function(){ body })()

Example

  Given the red checkbox can be located by id "red"
When I navigate to "https://automationintesting.com/selenium/testpage"
And I click the red checkbox
And I capture my favorite color in the red checkbox by js
"""
() => {
var color = element.value
if (!element.checked) color = "Blue"
return color;
}
"""
Then my favorite color should be "Red"