JS actions
I execute <js|javascript> on <element> "<function>"
Executes a javascript function on a web element.
I execute <js|javascript> on <element> "<function>"
Where
<element>is the name of the element to execute the function on<function>is the javascript function that will perform the action (can be in DocString position)- The function must use Arrow syntax and define a single argument for accepting the web element.
Example
Given the todo link can be located by xpath "//a[contains(text(),'TodoMVC')]"
When I navigate to "https://todomvc.com/examples/react/dist/"
And I execute js on the todo link "(elem) => elem.click()"
I execute <functionRef> on <element>
Executes a javascript function on a web element.
I execute <functionRef> on <element>
Where
<functionRef>is the name of the binding containing the javascript function to execute- The referenced function must use Arrow syntax and define a single argument for accepting the web element.
<element>is the name of the element to execute the function on
Example
Given the todo link can be located by xpath "//a[contains(text(),'TodoMVC')]"
And the click function is defined by js "(elem) => elem.click()"
When I navigate to "https://todomvc.com/examples/react/dist/"
And I execute the click function on the todo link
Deprecated since v4.16.0 and will be dropped in next major Gwen 5 release.<element> can be <actioned> by <javascript|js> "<script>"
Instead use one of:
I execute <js|javascript> on <element> "<function>"
I execute <functionRef> on <element>
Registers a javascript action on an element. When the action is performed, then the javascript will execute in place of the default behaviour.
Deprecated since v4.16.0 and will be dropped in next major Gwen 5 release.
<element> can be <actioned> by <javascript|js> "<script>"
Instead use one of:
I execute <js|javascript> on <element> "<function>"I execute <functionRef> on <element>
Where
<element>is the name of the element to register the action on<actioned>is one of:clickedto perform the action when the element is clickedright clickedto perform the action when the element is right clicked, since v2.8.0double clickedto perform the action when the element is double clicked, since v2.12.0submittedto perform the action when the form element is submittedchecked(ortickedsince v2.4.0) to perform the action when the checkbox element is tickedunchecked(oruntickedsince v2.4.0) to perform the action when the checkbox element is untickedselectedto perform the action when a dropdown option is selected in the elementdeselectedto perform the action when a mutli-select dropdown option is deselected in the element, since v2.13.0typedto perform the action when text is typed into the elemententeredto perform the action when text is entered into the elementtabbedto perform the action when the tab key is pressed in the element, since v2.17.1clearedto perform the action when the text is cleared in the elementmoved toto perform the action when the focus is moved to the element
<javascript|js>isjavascript(orjs, since v2.46.0)<script>is the javascript expression or function that will perform the action (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
returnprefix is required For a function, use either:
- Arrow syntax (preferred):
() => { body }(Since v3.56.0) - Or anonymous function syntax (legacy):
(function(){ body })()
- Arrow syntax (preferred):
- The reference to the element will be provided to the javascript through an implicit object named
Example
Given the submit button can be located by css ".submit"
And the submit button can be clicked by js "element.click()"
When I click the submit button