6
votes

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.

1

1 Answers

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