Selenium | Select item from listbox having dynamic id of options

Author - 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);


Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published.