java - Get the index number of first and last options listed in drop down menu -
i have find options listed first , last in dropdown menu using selenium webdriver.
li class="dropdown location" ul class="select" <li> class="dropdown location" <ul> class="select" <li> data-site="http://www.example.com" value="es">europe</li> <li> data-site ="http://www.example.com" value="sg">singapore</li>
there more 50 options. wanted find index number of singapore. there way find in webdriver?
yes, there way find index of particular value.
get options of list.
compare text of each element of list describable text, see below
select sel = new select(driver.findelement(by.cssselector("select[title='sort by']"))); list<webelement> list = sel.getoptions(); for(int i=0;i<list.size();i++){ if(list.get(i).gettext().equals("price")){ system.out.println("the index of selected option is: "+i); break; } }
Comments
Post a Comment