Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在watirwebdriver中运行JavaScript_Javascript_Ruby_Watir Webdriver - Fatal编程技术网

在watirwebdriver中运行JavaScript

在watirwebdriver中运行JavaScript,javascript,ruby,watir-webdriver,Javascript,Ruby,Watir Webdriver,我试图在我的watir ruby脚本(watir webdriver)中运行以下javascript代码。我正在尝试设置只读表单元素的值: @browser.execute_script("oFormObject = document.forms['/order/orders']; oFormElement = oFormObject.elements[\"order[begin_string]\"];") 当我这样做时,我得到一个错误,OfOrObject是未定义的。 但是在执行以下代码的过

我试图在我的watir ruby脚本(watir webdriver)中运行以下javascript代码。我正在尝试设置只读表单元素的值:

@browser.execute_script("oFormObject = document.forms['/order/orders']; oFormElement = oFormObject.elements[\"order[begin_string]\"];")
当我这样做时,我得到一个错误,OfOrObject是未定义的。
但是在执行以下代码的过程中,我没有得到任何错误:

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

我想在这之后得到表单元素,也就是当我得到一个错误时。我应该如何在我的watir脚本中运行多行JS代码。与选择表单一样,获取表单元素,然后设置该表单元素的值。

@browser.execute\u脚本谢谢。这很有帮助,我正在运行多行JS代码。
@browser.execute_script <<-JS
  oFormObject = document.forms['/order/orders'];
  oFormElement = oFormObject.elements[\"order[begin_string]\"];
JS