0

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

0

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){
        driver.findElement(By.xpath("//ul[@role='listbox']")).click();
        WebElement _element = driver.findElement(By.xpath("(//ul[@role='listbox']//li)[" + index+ "]")); 
        _element.click();
    }

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. Jul 16 '18 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. – Kshetra Mohan Prusty Jul 16 '18 at 11:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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