【问题标题】:watir webdriver select_list element not visible errorWatir webdriver select_list 元素不可见错误
【发布时间】:2013-06-25 20:12:56
【问题描述】:

我正在尝试使用 watir-webdriver 从选择列表中选择一个选项。

watir-webdriver gem 版本:0.6.4 mac osx lion 上的 Ruby 1.9.3

选择列表的HTML:

<select id="cc.expiryMonth" name="cc.expiryMonth">
<option value="0">Month</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
</select>

我使用的代码是

@browser.select_list(:name => "cc.expiryMonth").options[4].select

我遇到错误

Element is not currently visible and so may not be interacted with (Selenium::WebDriver::Error::ElementNotVisibleError)
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/fxdriver@googlecode.com/components/command_processor.js:7736:in `fxdriver.preconditions.visible'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/fxdriver@googlecode.com/components/command_processor.js:10437:in `DelayedCommand.prototype.checkPreconditions_'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/fxdriver@googlecode.com/components/command_processor.js:10456:in `DelayedCommand.prototype.executeInternal_/h'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/fxdriver@googlecode.com/components/command_processor.js:10461:in `DelayedCommand.prototype.executeInternal_'
  [remote server] file:///var/folders/_c/j__zdvw93gqgyyvzwmmgtwwr0000gn/T/webdriver-profile20130620-1023-1s8kag6/extensions/fxdriver@googlecode.com/components/command_processor.js:10401:in `DelayedCommand.prototype.execute/<'
  ./features/step_definitions/Wotif_FlightSearch_DOM_steps.rb:145:in `/^I enter all details on booking page$/'

浏览了gem库中的watir-webdriver代码,用尽了所有选择选项的方法,都抛出了同样的错误。

@browser.select_list(:name => "cc.expiryMonth").focus

成功,但选择选项会引发元素不可见错误。 也尝试了 send_keys 失败。 希望有任何关于如何处理这个问题的建议

更新:

@browser.select_list(:name => "cc.expiryMonth").options[8].value

返回值但是

@browser.select_list(:name => "cc.expiryMonth").options[8].select

@browser.select_list(:name => "cc.expiryMonth").select @browser.select_list(:name => "cc.expiryMonth").options[8].value returns element not found error    

【问题讨论】:

  • 选择元素是否始终可见,或者您是否必须执行操作才能使选择元素可见?您尝试的 html 示例和代码可以自行运行,因此导致失败的页面还有其他问题。
  • 它位于屏幕底部,webdriver 正在向下滚动并成功设置其他 select_lists .....

标签: selenium-webdriver watir-webdriver


【解决方案1】:

你试过了吗:

@browser.select_list(:name => "cc.expiryMonth").select '04'

甚至

b = Watir::Browser.start 'bit.ly/watir-webdriver-demo'
s = b.select_list :name => 'cc.expiryMonth'
s.select '04'
s.selected_options

告诉我怎么了

【讨论】:

  • 嗨,尝试了选项 .select '04' 选项。它抛出相同的错误元素不可见错误。元素就在屏幕上,但 webdriver 无法识别它。尝试睡眠并等待它存在?并且可见?
  • @rails4sandeep,有一些等待是的,看看here
【解决方案2】:

这可能是时间问题。试试这个:

@browser.select_list(:name => "cc.expiryMonth").options[4].when_present.select

更多信息http://watirwebdriver.com/waiting/

【讨论】:

  • 感谢您的回复。使用when_present方法时,在最大超时时间之后执行timed_out
【解决方案3】:

我想知道页面上是否有多个具有此名称的选择列表,而 Watir-webdriver 正在等待第一个元素,但可见的实际上是第二个。

试试这个:

 p @browser.select_lists(:name => "cc.expiryMonth").count

它在命令提示符/mac 等效项中返回的值是否高于 1?如果是这样,您可以使用索引来选择您想要的那个

@browser.select_list(:name => "cc.expiryMonth", :index => 1).select("04")

【讨论】:

    【解决方案4】:

    我终于能够通过关注 stackoverflow 上的其他问题之一来解决问题,其中建议使用 javascript 来选择选择列表中的选项。没有其他工作。很高兴终于有工作了

    【讨论】:

    • 你能告诉我链接以及你是如何在 watir-webdriver 中使用 java 脚本完成的
    • 该链接将非常有用。你如何使用来自 watir 的 javascript?
    • 对不起,在 watir-webdriver 代码中使用 javascript 的方法是 @b.driver.execute_script('write your javascript code here')
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    相关资源
    最近更新 更多