简体   繁体   中英

Running JavaScript in watir-webdriver

I am trying to run the following piece of javascript code in my watir ruby script(watir webdriver). I am trying to set the values of a read only form element:

@browser.execute_script("oFormObject = document.forms['/order/orders']; oFormElement = oFormObject.elements[\"order[begin_string]\"];")

When I do this I get the error, oFormObject is undefined.
But during executing the following code I didn't get any error:

@browser.execute_script("oFormObject = document.forms['/order/orders'];")

I want to get the form elements after this that is when I get an error. How should I run multiple lines of JS code in my watir script. Like select a form, get a form element and then set the value of that form element.

@browser.execute_script <<-JS
  oFormObject = document.forms['/order/orders'];
  oFormElement = oFormObject.elements[\"order[begin_string]\"];
JS

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM