无法在 select 列表和 select 中找到的元素上获取 "true condition"

Unable to get "true condition" on a found element in a select list and select it

我将 Watir 6 与 Rspec 一起使用,但在访问 select 列表和 select 选择其中一个选项时遇到问题。

URL是:https://www.fundingcircle.com/businesses/apply?video=true

有问题的失败代码是:

browser.select_list(name: 'loan_product').select('Working capital')

HTML:

<select name="loan_product" required="" ng-model="prequal.borrower.loan_product" ng-options="product as product.label for product in prequal.loanProducts" styled-select="" placeholder="Please select..." fc-input="" class="ng-scope ng-pristine ng-invalid ng-invalid-required fc-touched">
<option value="?" selected="selected" label=""></option><option value="0" label="Working capital">Working capital</option><option value="1" label="Expansion/growth">Expansion/growth</option><option value="2" label="Refinancing a loan">Refinancing a loan</option><option value="3" label="Asset finance">Asset finance</option><option value="4" label="Tax payment">Tax payment</option><option value="5" label="Commercial mortgage">Commercial mortgage</option><option value="6" label="Other">Other</option></select>

无论我尝试更改代码多少次,我一直收到的错误是:

This code has slept for the duration of the default timeout waiting for an Element to be present. If the test is still passing, consider using Element#exists? instead of rescuing UnknownObjectException
Watir::Exception::UnknownObjectException: element located, but timed out after 30 seconds, waiting for true condition on {:name=>"loan_product", :tag_name=>"select"}
from /Users/.rvm/gems/ruby-2.2.2/gems/watir-6.0.2/lib/watir/elements/element.rb:528:in `rescue in wait_for_present'

元素存在并且所有 select 列表选项显示为 true,但不幸的是,根据测试,它们似乎不可见或不存在。我觉得最后的选择是操纵 javascript,但如果可以的话,我不想走这条路。如果有人能让我走上正确的道路并建议我如何解决这个问题,我将不胜感激。任何帮助将不胜感激。

这很奇怪。在我的 mac 中,select 列表在 Firefox 中显示为可见,但在 Chrome 中不可见。 Watir 在尝试单击该选项之前检查 select 列表是否可见。 option 元素在 Selenium 中实现,因此它始终 return 可见。

所以这对你有用:

browser.option(label: 'Working capital').click

我不确定它们为何不同,或者 Windows 与 Chrome 有什么问题。大概 chromedriver 使用与 geckodriver 相同的 isDisplayed javascript 代码。您可能会将其作为 chromedriver 错误提出。