Yulia Yulia - 4 years ago 326
Ruby Question

How to execute Javascript in Ruby written Webdriver test?

Is there a known solution to perform Eval (Javascript execution) in Webdriver, ruby bindings? The equivalent of the following example in Java.

WebElement element = driver.findElement(By.id( "foo" ));
String name = (String) ((JavascriptExecutor) driver).executeScript(
"return arguments[0].tagName" , element)

Answer Source

The equivalent Ruby would be:

 name = driver.execute_script("return arguments[0].tagName" , element)

(to get the tag name you could also just call element.tag_name)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download