无法使用 watir 网络驱动程序在 iframe 中填写只读文本框

Unable to fill a text box which is read only and in iframe using watir webdriver

本文关键字:只读 文本 iframe watir 驱动程序 网络      更新时间:2023-09-26

我在iframe内有一个只读文本字段要填充。请在下面找到导航。

  1. 网址为"http://www.broadwaylofts.com/apartments/unitLevel.do?lid=en_US&pid=3015&uid=1866117&msud=Q%20&adAction=initial"

  2. 点击"每月价格"按钮。

  3. 您将能够在叠加层上看到一个文本框。

我正在尝试填充该文本框,但无法

以下是我尝试的方法:

  1. 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
  1. b.execute_script("window.document.getElementById('actionForm_moveindate').value = '03/20/2015';")

它抛出以下错误

Selenium::WebDriver::Error::JavascriptError: window.document.getElementById(...) is null
  1. 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';")