我正在使用带有Rspec的Watir 6,而我无法访问选择列表并选择其中一个选项。
网址为: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'
元素存在且所有选择列表选项显示为true,但不幸的是,根据测试,它们似乎不可见或不存在。我觉得最后一个选项是操纵javascript,但如果我可以帮助它,我不想走这条路。如果有人能让我走上正确的道路并建议如何解决这个问题,我将非常感激。任何帮助将不胜感激。
答案 0 :(得分:2)
这很奇怪。在我的Mac上,选择列表在Firefox中显示为可见,但在Chrome中不显示。在尝试单击选项之前,Watir检查选择列表是否可见。选项元素在Selenium中实现,因此它将始终返回为可见。
所以这对你有用:
browser.option(label: 'Working capital').click
我不确定他们为什么会有所不同,或者Windows和Chrome有什么问题。据推测,chromedriver正在使用与geckodriver相同的isDisplayed javascript代码。你可能会把它作为一个chromedriver bug。