无法从 watir 的下拉列表中选择数量

Trouble selecting quantity out of drop down in watir

我从未 运行 遇到过能够 select 下拉列表中的值的问题,所以我不确定这有何不同。首先,这是我正在使用的 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>

我想要select一个特定的选项。在本例中,我为数量设置了一个变量,并将其设置为 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

下拉框打开,我只是无法获取要 selected 的值。

我尝试了一些其他变体,但 none 奏效了。任何帮助将不胜感激。希望有一些我遗漏的小东西。

谢谢!

首先,在这段代码之前,HTML必须有一个select列表,也许这个select列表有属性"display: none",那么你可以:

  1. browser.execute_script("document.getElementById('[id of this select list ]').style.display = 'block';")

  2. browser.select(:id => '[id of this select]').option(:text => '[text that you need]').select