How can i select a value from the dropdown using selenium web driver enter image description here

1 Answer 1


Here the drop down is implemented using a ul and li, so you can't use WebDriver's Select class, it will throw UnexpectedTagNameException if you do so.

What you need to do in this case, write a custom select method like below to help you.

    public void select_by_index(int index){
        WebElement _element = driver.findElement(By.xpath("(//ul[@role='listbox']//li)[" + index+ "]")); 

So what we are doing here:

  • Click the drop down to show all the options, so that they are visible.
  • We are dynamically creating xpath for different element in the drop-down list and then clicking on the elements.
  • If you pass 2 as argument, it will select 'Change of Mind' from the drop-down and so on.

Try this and let us know if this works in your case. The code is just for illustration purpose.

  • The code in your example does not seem to be c# code. However OP asks about c#
    – Alexey R.
    Commented Jul 16, 2018 at 10:44
  • My intention was to give an idea how to solve the problem. The code is written in Java, however the same can be translated to C#. Hope that's not a problem. Commented Jul 16, 2018 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.