[英]Selenium isSelected() method is lying
我正在嘗試使用硒測試一組單選按鈕。 我已經將它們分組在一個列表中
@FindBy(xpath = "//ux-button-group//input[@name='options']")
private List<WebElement> granularity;
當我測試是否選擇了第一個選項時,它會返回false
。
assertTrue(granularity.get(0).isSelected(), "Granularity should have selected the first option");
我已經調試並看到,如果我嘗試使用最后一個元素 (3),那么它會給我true
。 您可能會像我一樣認為列表中的順序以某種方式顛倒了,但事實並非如此。 我已經通過檢索列表中每個元素的 id 進行了檢查,並且它們的順序正確。 我還嘗試檢索“已檢查”屬性,但這是錯誤的。 前 3 個按鈕返回null
,最后一個返回true
!
網址:
<div data-toggle="buttons" class="ux-button-group btn-group btn-lg" data-e2e="ux-button-group">
<!----><!---->
<label class="btn btn-primary btn-lg ng-star-inserted active">
<input autocomplete="off" name="options" type="radio" id="shared.granularity.0" checked="true"> Daily <!---->
</label>
<label class="btn btn-primary btn-lg ng-star-inserted">
<input autocomplete="off" name="options" type="radio" id="shared.granularity.1" checked="false"> Weekly <!---->
</label>
<label class="btn btn-primary btn-lg ng-star-inserted">
<input autocomplete="off" name="options" type="radio" id="shared.granularity.2" checked="false"> Monthly <!---->
</label>
<label class="btn btn-primary btn-lg ng-star-inserted">
<input autocomplete="off" name="options" type="radio" id="shared.granularity.3" checked="false"> Yearly <!---->
</label>
<!----><!---->
</div>
嗯,xpath 似乎不正確, ux-button-group
應該是一個標簽,可以像這樣使用它。
xpath 應該是:
//div[contains(@class, 'ux-button-group')]//input[@name='options']
或者更簡單的css:
.ux-button-group input[name=options]
或其他 css(更好,因為您可以從 id 名稱中看到代表什么):
input[id*='shared.granularity']
如果可能並且沒有任何限制,也可以嘗試使用 selenium 3.141.59。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.