我在 iframe 中有一个要填充的只读文本字段。请找到下面的导航。
点击“每月价格”按钮。
您将能够在叠加层上看到一个文本框。
我正在尝试填充该文本框,但无法
以下是我尝试过的方法:
-
b.iframe(:class => "lb_iframe_pricegrid").execute_script("window.document.getElementById('actionForm_moveindate').value = '03/20/2015';")
它抛出以下错误
Selenium::WebDriver::Error::JavascriptError: window.document.getElementById(...) is null
-
b.execute_script("window.document.getElementById('actionForm_moveindate').value = '03/20/2015';")
它抛出以下错误
Selenium::WebDriver::Error::JavascriptError: window.document.getElementById(...) is null
-
b.iframe(:class => "lb_iframe_pricegrid").text_field.set "02/20/2015"
下面是我遇到的错误
Watir::Exception::ObjectReadOnlyException: object is read only {:tag_name=>"input or textarea", :type=>"(any text type)"}
from /Library/Ruby/Gems/2.0.0/gems/watir-webdriver-0.6.10/lib/watir-webdriver/elements/element.rb:553:in `assert_writable'
from /Library/Ruby/Gems/2.0.0/gems/watir-webdriver-0.6.10/lib/watir-webdriver/user_editable.rb:12:in `set'
from (irb):19
from /usr/bin/irb:12:in `<main>'
有什么想法或建议可以让它发挥作用吗?
最佳答案
您的代码应如下所示:
b.execute_script("window.frames[0].document.getElementById('actionForm_moveindate').value = '03/20/2015';")
关于javascript - 无法使用 watir webdriver 填充 iframe 中的只读文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28144152/