Selenium webdriver watir webdriver选择列表元素不可见错误

Selenium webdriver watir webdriver选择列表元素不可见错误,selenium-webdriver,watir-webdriver,Selenium Webdriver,Watir Webdriver,我正在尝试使用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> <opt

我正在尝试使用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>
我犯了一个错误

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$/'
已成功,但选择选项会引发元素不可见错误。 还尝试发送_密钥,但未成功。 如果您对如何处理此问题有任何建议,我们将不胜感激

更新:

@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 '04'
甚至

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

告诉我发生了什么事,可能是时间问题。试试这个:

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

更多信息请访问

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

尝试一下:

 p @browser.select_lists(:name => "cc.expiryMonth").count
在命令提示符/mac等效项中,它是否返回大于1的值?如果是这样,您可以使用索引来选择所需的索引

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

我最终能够解决这个问题,方法是遵循stackoverflow上的其他问题之一,其中建议使用javascript选择选择列表中的选项。其他任何问题都不起作用。令人高兴的是,最终起作用的是select元素始终可见,还是您必须执行操作才能使select元素可见看得见的您尝试的html示例和代码本身可以正常工作,因此导致失败的是页面的其他方面。它位于屏幕底部,Web驱动程序正在向下滚动,设置其他选择列表在那里成功…感谢您的回复。使用when_present方法时,执行在最长超时时间后超时。请尝试该选项。选择“04”选项。它抛出相同的错误元素不可见错误。元素就在屏幕上,但webdriver无法识别它。是否尝试睡眠并等待它存在?可见吗?@rails4sandeep,还有一些等待是的,看一看,你能告诉我这个链接,以及你是如何在watir webdriver中使用java脚本实现的吗?这个链接非常有用。如何使用来自watir的javascript?对不起,伙计们,在watir webdriver代码中使用javascript的方法是执行脚本(“在此处编写javascript代码”)
@browser.select_list(:name => "cc.expiryMonth").options[4].when_present.select
 p @browser.select_lists(:name => "cc.expiryMonth").count
@browser.select_list(:name => "cc.expiryMonth", :index => 1).select("04")