Selenium | Select item from listbox having dynamic id of options

| By Webner

In Selenium script if we want to select a value in a dropdown but value of attribute ‘id’ of the options in the dropdown keep on changing every time then we need to find the option based on some other locator instead of ‘id’. In sample code below option is being searched on the basis of value for example :

//locate the option based on value instead of id for example 

String a = selenium.getText("//option[@value='abcd']");

//select the option

selenium.AddSelection ("ctl00_mainContentPlaceHolder_lstCategory",a);


Leave a Reply

Your email address will not be published. Required fields are marked *