6

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 Answer 1

10
@browser.execute_script <<-JS
  oFormObject = document.forms['/order/orders'];
  oFormElement = oFormObject.elements[\"order[begin_string]\"];
JS
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It is helpful and multiple lines of JS code is running for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.