[WebUI] Execute JavaScript
Description
Execute JavaScript on the currently selected frame or window. The provided script fragment will be executed as the body of an anonymous function.
Keyword name: executeJavaScript
Parameters
Parameter | Parameter Type | Required | Description |
---|---|---|---|
script | String | Yes | The JavaScript to execute. |
argument | List | Yes | The arguments to the script. Can be empty or null. |
flowControl | FailureHandling | Optional | Specify failure handling schema to determine whether the execution should be allowed to continue or stop. |
Returns
- Boolean, Long, Double, String, List, Web Element, or Null.
Example
Make an alert on the web page:
'Use Javascript to make an alert'
WebUI.executeJavaScript("alert('This is an alert')", null)
Return WebElement
based on its id:
WebElement element = WebUI.executeJavaScript("return document.getElementById('someId');", null)
Interact with returned WebElement
:
WebElement element = WebUiCommonHelper.findWebElement(findTestObject('your/object'),30)
WebUI.executeJavaScript("arguments[0].style.border='3px solid blue'", Arrays.asList(element))
Click on returned WebElement
:
WebElement element = WebUiCommonHelper.findWebElement(findTestObject('your/object'),30)
WebUI.executeJavaScript("arguments[0].click()", Arrays.asList(element))