jnicklas/capybara — Issue #563: Capybara bindings to WebDriver do not allow the native functionality of the WebDriver#execute_script function
Author: wokkaflokka
Created: 2011-12-09 20:55:57+00:00
State: open

In WebDriver, one can call the 'execute_script' method as follows:
button = driver.find_element(:id, "plainButton")
driver.execute_script("return arguments[0].innerText;", button)

In Capybara with driver set to :selenium, the following method's of execution return a "Wrong # of Arguments (2 for 1)" error:
1)
scripts = page.all(:xpath, "//script[contains(@type,'text/javascript') and contains(text(),'Highcharts.StockChart')]")
scripts.each { |chart|
code = evaluate_script("return arguments[0].innerHTML", chart)
}

2)
scripts = page.all(:xpath, "//script[contains(@type,'text/javascript') and contains(text(),'Highcharts.StockChart')]")
scripts.each { |chart|
code = page.driver.execute_script("return arguments[0].innerHTML", chart.native)
}

Currently, the only way to achieve this is by directly accessing the WebDriver object itself, as follows:

webdriver = page.driver.instance_eval("@browser")
code = webdriver.execute_script("return arguments[0].innerHTML", chart.native)

It would be nice if the bindings could be brought up to speed.

Many thanks!