![](/img/trans.png)
[英]List WebElement always selecting first element from the drop-down but i want to select 4th element
[英]Selecting an element from a drop-down with Protractor
我在使用Angular構建的應用程序的一頁上使用常規Selenium Webdriver時遇到了嚴重麻煩。 我在pom.xml中添加了ngwebdriver的依賴關系,到目前為止,我已經解決了一些問題。 僅通過下拉菜單,我仍然沒有弄清楚該如何做。 這是我正在談論的下拉列表:
<d3-data-list _nghost-c8="" ng-reflect-data-source="[object Object]" ng-
reflect-html-id="documents_glossary_entityPicke" ng-reflect-allow-blank-
option="true" ng-reflect-blank-option-text="All entities" ng-reflect-default-
caption="Choose an entity"><div _ngcontent-c8="" class="dropdown d3-data-
list" id="documents_glossary_entityPicker">
<button _ngcontent-c8="" aria-expanded="true" aria-haspopup="true" class="btn btn-default dropdown-toggle" data-toggle="dropdown" type="button" id="documents_glossary_entityPicker_button">
All entities
<span _ngcontent-c8="" class="caret"
id="documents_glossary_entityPicker_caret"></span>
</button>
<ul _ngcontent-c8="" aria-labelledby="dropdownMenu1" class="dropdown-menu"
ng-reflect-infinite-scroll-handle-in-progress="false"
id="documents_glossary_entityPicker_dropdown">
<!--bindings={
"ng-reflect-ng-if": "true"
}--><li _ngcontent-c8="">
<a _ngcontent-c8=""
id="documents_glossary_entityPicker_blank_option">All entities</a>
</li>
那么下拉菜單中的選項如下:
</li><li _ngcontent-c8="">
<a _ngcontent-c8="" id="documents_glossary_entityPicker_option_2">Entity three</a>
</li>
問題是我的下拉菜單中的元素順序無法保持,因為如果在另一個頁面上編輯了一個元素(實體),則該元素將位於列表的底部。 因此,我永遠無法真正知道我的元素在下拉列表中的確切位置。
是否有類似browser.findElement(ByAngular.buttonText("text"))
類的東西可以使用? 謝謝。
對於.filter()
您的代碼應如下所示:
element.all(by.css('ul li a')).filter(function (elm) {
return elm.getAttribute('value').then(function (text) {
return text === "TheValueYouLookFor";
});
}).first().click();
我沒有.filter
測試過這個.filter
,但是從Protractor文檔中可以很直接地看出來。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.