How to Execute JavaScript in Ruby Written Webdriver Test

How to execute JavaScript in Ruby written Webdriver test?

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)

How to execute javascript for watir webdriver to change text inside a span id

You appear to just be missing the quotations around the script - ie execute_script expects a string:

browser.execute_script('$("#CSVFileName").text("template.csv")')

How do you perform javascript tests with Minitest, Capybara, Selenium?

Hmm I noticed a couple lines in the docs that seem to say that the above can only be done in Rspec

However, if you are using RSpec or Cucumber, you may instead want to consider leaving the faster :rack_test as the default_driver, and marking only those tests that require a JavaScript-capable driver using :js => true or @javascript, respectively.

Ruby Selenium WebDriver - get return value of execute_script

You just need to add the return:

driver.execute_script 'return $.active'


Related Topics



Leave a reply



Submit