Reputation: 93
Please find the html code below :
<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>
From the below code i will get some list of options, and i have to get the selected values using XPath
<option ng-repeat="dealer in mainStoreDealerList" value="{{dealer}}">{{dealer.id}} - {{dealer.name}}</option>
Please find by below code that am using to get the selected value
@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....");
}
And am getting the below results while am printing it.
Xpath--->Proxy element for: org.openqa.selenium.support.pagefactory.DefaultElementLocator@d93a6a5
and its getting failed with the below error :
Results :
Tests in error:
Unable to locate element: {"method":"xpath","selector":"//*[@id=\"select2-result-label-90\"]"}
Command duration or timeout: 100.29 seconds
Upvotes: 1
Views: 205
Reputation: 105
Try using the "ID" selector ,sometimes when xpath fails we use CSS properties to select an element.
@FindBy(id="selected_dsd")
Upvotes: 1
Reputation: 8414
There's no element with select2-result-label-90
id in your HTML. If you are trying to select the "select" element, the proper xpath would be
@FindBy(xpath = "//*[@id='selected_dsd']")
Upvotes: 0