我从未遇到过能够在下拉列表中选择值的问题,因此我不确定这是如何不同的。首先,这是我正在使用的HTML:
<div class="hn-select-content hn-select-expand" ng-class="{'open-to-left':openToLeft, 'expand-to-left':expandToLeft}" ng-transclude="" style="">
<ul class="qty-discount whiteBackground border border-hn-secondary-lt text-small ng-scope" scroll-lock="">
<li float-container="">
<div class="float-cont">
<ul class="text-small">
<li class="selected ng-isolate-scope HN-Item-Opt-Sel" li="" <="" on-option-select="changeQuantity(val)" value="1" option="1" ng-class="{'HN-Item-Opt-Sel selected':atcData.quantity == 1}" hn-select-option="">
<div class="hn-select-option ng-binding">1</div>
</li>
</ul>
</li>
<li float-container="">
<div class="text-hn-red float-cont">
<div scroller="qty-discount" floater="" style="">
<span> 10% Off </span>
</div>
<div></div>
</div>
<ul class="text-small">
<li class="ng-isolate-scope" li="" <="" on-option-select="changeQuantity(val)" value="2" option="2" ng-class="{'HN-Item-Opt-Sel selected':atcData.quantity == 2}" hn-select-option="">
<div class="hn-select-option ng-binding">2</div>
</li>
我想选择一个特定的选项。在这种情况下,我有一个数量的变量集,它被设置为2.
这是失败的步骤中的代码:
@browser.div(:id, 'hn_modal_contentIV').div(:text, '1').when_present.click
@browser.ul(:class, 'whiteBackground border border-hn-secondary-lt text-small ng-scope').div(:text, quantity).when_present(5).click
@browser.span(:class, 'redText floatRight marginTopOnly3px').wait_until_present(10)
这是我收到的错误:
Watir::Wait::TimeoutError: timed out after 5 seconds, waiting for {:text=>"2", :tag_name=>"div"} to become present
下拉框打开,我无法获得要选择的值。
我尝试过其他一些变体,但都没有。任何帮助将不胜感激。希望我能错过一些小事。
谢谢!
答案 0 :(得分:1)
首先,在此代码之前,HTML必须有一个选择列表,也许这个选择列表具有属性"display: none"
,然后您可以:
browser.execute_script("document.getElementById('[id of this select list ]').style.display = 'block';")
browser.select(:id => '[id of this select]').option(:text => '[text that you need]').select