请在下面找到html代码:
<div class="col-lg-3 col-md-4">
<select ui-select2="ui-select2" name="dealer" id="selected_dsd" ng-init="delegate.init()" ng-model="selectedMainStoreTest" ng-change="delegate.getBranchDealers()">
<option value="">{{'manageChargeCodes.form.fields.choose' |translate}}</option>
<option ng-repeat="dealer in mainStoreDealerList" value="{{dealer}}">{{dealer.id}} - {{dealer.name}}</option>
</select>
</div>
从下面的代码中,我将获得一些选项列表,并且我必须使用XPath获取选定的值
<option ng-repeat="dealer in mainStoreDealerList" value="{{dealer}}">{{dealer.id}} - {{dealer.name}}</option>
请按以下代码查找用于获取所选值的代码
@FindBy(xpath = "//*[@id=\"select2-result-label-90\"]")
private WebElement mainStoreDealersSelector;
public void selectMainStoreDealers(String mainStoreDealer) {
System.out.println("Xpath--->"+mainStoreDealersSelector);
selectFromDropDown(mainStoreDealersSelector, mainStoreDealer);
System.out.println("Completed....");
}
在打印时得到以下结果。
Xpath--->Proxy element for: org.openqa.selenium.support.pagefactory.DefaultElementLocator@d93a6a5
并由于以下错误而失败:
Results :
Tests in error:
Unable to locate element: {"method":"xpath","selector":"//*[@id=\"select2-result-label-90\"]"}
Command duration or timeout: 100.29 seconds
答案 0 :(得分:1)
尝试使用“ ID”选择器,有时xpath失败时,我们会使用CSS属性选择元素。
@FindBy(id="selected_dsd")