Running JavaScript in watir-webdriver
Asked Answered
H

1

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.

Homologue answered 15/2, 2012 at 15:39 Comment(0)
T
10
@browser.execute_script <<-JS
  oFormObject = document.forms['/order/orders'];
  oFormElement = oFormObject.elements[\"order[begin_string]\"];
JS
Tuberous answered 15/2, 2012 at 16:0 Comment(1)
Thanks. It is helpful and multiple lines of JS code is running for me.Bataan

© 2022 - 2024 — McMap. All rights reserved.