Skip to main content

Regex capture

I capture the text in <textRef> by regex "<expression>" as <name>

Captures the referenced text using the given regex expression 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.
  • <expression> is the regex selector expression
  • <name> is the name to bind the captured value to

Example

  Given the date is "2021-09-22"
When I capture the text in the date by regex "(\d{4})" as the year
Then the year should be "2021"
I capture the text in <element> by regex "<expression>" as <name>

Captures text content from a web element using the given regex expression and binds it to the given name in the global scope.

Where

  • <element> is the name of the element to capture text from
  • <expression> is the regex selector expression
  • <name> is the name to bind the captured value to

Example

  # assuming a web element contains date: 2021-09-22
Given the date field can be located by class "date"
When I capture the text in the date field by regex "(\d{4})" as the year
Then the year should be "2021"