[英]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.