java - finding xpath of dropdown for application developed in angular -


html code dropdown:

 <div class="margin-bottom">        <select ng-class="{'invalid-select':(selecteditem == '-1' &amp;&amp; submitted)}" class="select-lg select-custom ng-pristine ng-untouched ng-valid ng-not-empty ng-valid-required" name="items" ng-model="selecteditem" ng-options="item.id item.name item in items" required="" ng-change="onchange()" style="">       <option value="" selected="selected" class="">select one</option>      <option label="stage test" value="number:682">stage test</option>      <option label="automation 1" value="number:687">automation 1</option>      <option label="automation 3" value="number:688">automation 3</option>      <option label="new co" value="number:690">new co</option></select>  </div> 

i using xpath element using :

select companyselect = new select(driver.findelement(by.xpath("//*[@ng-model='selecteditem']"))); 

here answer question:

while constructing xpath select element, have tried take of attribute ng-model. attribute pretty common applications built angularjs , when used attribute construct xpath may not identify element unique element on html dom.

as per html provided, select tag have name. per best practices should out id or name locator first unique. consider keeping steps simple easy debug incase of errors. here sample code block per html selects stage test dropdown:

webelement my_dropdown = driver.findelement(by.name("items")) select companyselect = new select(my_dropdown); companyselect.selectbyvisibletext("stage test"); 

let me know if answers question.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -