我有一个地址下拉列表。如果我输入的地址没有列出,那么有一个页脚选项“地址没有列出?显示更多?”当我选择该选项时,它会给我一个手动输入地址的选项。我想选择“未列出的地址?显示更多?”选项。
在我的代码中,我有以下支持方法来按索引选择地址。但我想根据给定的文本进行选择。非常感谢你的帮助。谢谢
public static async chooseDropdownItemByIndex(dropdown:
ElementArrayFinder, index: number) {
const item = await dropdown.$$('li').get(index);
await ActionUtil.waitForElementToBeInteractable(item);
return item.click();
}dropdown: ElementArrayFinder,类似于element.all(by.css('.currentAddress-field hmy-address-autocomplete'))
我的标签如下所示
<hmy-address-autocomplete input-id="currentAddress-input" name="currentAddress" branch="AU" ng-model="vm.model" no-results="vm.toggleEntryMode()" required="" strict="" class="ng-pristine ng-untouched ng-isolate-scope ng-not-empty ng-valid ng-valid-required" style="">
<input type="text" id="currentAddress-input" name="currentAddress" ng-required="vm.required" ng-model="vm.model" ng-keypress="vm.clearSelectedOption()" ng-focus="vm.inputFocused()" placeholder="" autocomplete="off" class="ng-dirty ng-valid-parse ng-not-empty ng-valid-required ng-valid ng-touched" required="required" style="">
<hmy-loading-spinner ng-class="{ active: vm.isLoading }" class="" style="">
</hmy-loading-spinner>
<hmy-dropdown items="vm.options" item-selected="vm.itemSelected(item)" empty-text="No results" class="ng-isolate-scope">
<ul ng-class="{open: vm.isOpen}" ng-mouseout="vm.clearCurrentItem()" class="" style="">
<li ng-repeat="item in vm.items" ng-class="{hover: vm.getCurrentItem() === item}" ng-mousedown="vm.selectItem(item)" ng-mouseover="vm.setCurrentItem(item)" class="ng-binding ng-scope" style=""> level 13 Carahers Lane, THE ROCKS NSW 2000 </li>
<li ng-repeat="item in vm.items" ng-class="{hover: vm.getCurrentItem() === item}" ng-mousedown="vm.selectItem(item)" ng-mouseover="vm.setCurrentItem(item)" class="ng-binding ng-scope" style=""> level 15 Carahers Lane, THE ROCKS NSW 2000 </li>
<li class="footer" ng-transclude="footer" ng-mouseover="vm.clearCurrentItem()">
<hmy-dropdown-footer ng-click="vm.includePostalAddresses()" ng-if="vm.excludePostal && vm.hasOptions()" class="ng-scope" style=""> Address not listed? Show more </hmy-dropdown-footer>
</li>
</ul>
</hmy-dropdown>
</hmy-address-autocomplete>发布于 2019-07-22 15:48:51
大多数情况下,cssContainingText是通过文本查找元素的最简单方法。
在您的示例中,它将如下所示(注意字符串开头和结尾的空格)
//cssContainingText
element(by.cssContainingText("hmy-dropdown-footer", " Address not listed? Show more "));
//xpath
element(by.xpath("//hmy-dropdown-footer[text()=' Address not listed? Show more ']");https://stackoverflow.com/questions/57138847
复制相似问题