Skip to end of metadata
Go to start of metadata

Description  

Execute JavaScript on the currently selected frame or window. The provided script fragment will be executed as the body of an anonymous function.

Since 5.0

Parameters  

ParamParam TypeMandatoryDescription
scriptStringRequiredThe JavaScript to execute.
argumentListRequiredThe arguments to the script. Can be empty or null.
flowControlFailureHandlingOptionalSpecify 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))
  • No labels