2

extjs コンボ ボックスからオプションを選択しようとしています。
以下のコードlistElementsでは、すべてのオプションではなく、目に見えるオプション (画面に表示される) のみを指定しています。
ここでは、画面で使用可能なオプションの 1 つを選択するように制限されています。
リストの一番下にある値を選択したい。
リストを下にドラッグして目的のオプションを選択するオプションが見つかりません。

 List<WebElement> listElements = TestUtil.getWebDriver().findElements((By.className("x-boundlist-item")));
        for(WebElement ele : listElements){
            if(ele.getText().equals(TestUtil.getValue(DateTimeConstants.TIMEZONE_INPUT_VALUE))){
                ele.click();
                break;
            }
        }

html を見つけてください:

これは、コンボ ボックスの html です。

<input id="currentTimezone-inputEl" class="x-form-field x-form-text x-form-focus x-field-form-focus x-field-default-form-focus" type="text" style="width: 100%; -moz-user-select: text;" name="dateTimeData.selectedTimezone" value="-- Please Select --" autocomplete="off" aria-invalid="false" data-errorqtip="">  

オプションは以下のように利用できます。

<div id="ext-gen1024" class="x-reset">
<div id="ext-gen1074" class="x-reset">
<div id="ext-gen1076" class="x-css-shadow" role="presentation" style="z-index: 19000; left: -9999px; top: -9995px; width: 355px; height: 296px; box-shadow: 0px 0px 4px rgb(136, 136, 136); display: none;"></div>
<div id="ext-gen1079" class="x-css-shadow" role="presentation" style="z-index: 19000; left: 20px; top: 321px; width: 355px; height: 296px; box-shadow: 0px 0px 4px rgb(136, 136, 136); display: none;"></div>
<div id="boundlist-1022" class="x-boundlist x-boundlist-floating x-layer x-boundlist-default" tabindex="-1" style="left: 20px; top: 317px; width: 355px; z-index: 19001; height: 300px; display: none;">
<div id="boundlist-1022-listEl" class="x-boundlist-list-ct" style="overflow: auto; height: 299px;">
<ul>
<li class="x-boundlist-item" role="option">Africa/Abidjan</li>
<li class="x-boundlist-item" role="option">Africa/Accra</li>
<li class="x-boundlist-item" role="option">Africa/Addis_Ababa</li>
<li class="x-boundlist-item" role="option">Africa/Algiers</li>
<li class="x-boundlist-item" role="option">Africa/Asmara</li>

<li class="x-boundlist-item x-boundlist-selected" role="option">America/St_Lucia</li>
</div>
</div>
</div>
4

2 に答える 2

2

はい、この問題を再現できます。その理由は、Selenium が不可視要素をクリックしないためです。不可視要素の各テキストも空になります。

ここでは、ほとんどのコンボ リスト要素が非表示になっているため、ele.getText()何も取得できません。その結果、テキストを目的のテキストと比較することができなくなります。

ただし、回避策として、 を使用ele.getText()してテキストを取得せずtextContentに、要素の属性を使用してテキストを取得してみてください。Actions click()また、Selenium は非表示の要素をクリックしないため、通常の ではなくを使用する必要がありますclick()。以下は、その方法です。

List<WebElement> listElements = TestUtil.getWebDriver().findElements((By.cssSelector(".x-boundlist:not([style*='display: none'])")));
    for(WebElement ele : listElements){
        if(ele.getAttribute("textContent").equals(TestUtil.getValue(DateTimeConstants.TIMEZONE_INPUT_VALUE))) {
            // print out ele.getAttribute("textContent") if you want
            // ele.click(); ElementNotVisible exception may be thrown
            new Actions(TestUtil.getWebDriver()).click(ele).perform();
            break;
        }
    }
}
于 2013-07-19T22:41:08.083 に答える