Here the drop down is implemented using a ul and li, so you can’t use 's Select , 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.



Source link https://sqa.stackexchange.com/questions/34760/how-can-i-get-the-value-from-a--of--class-in--webdriver

LEAVE A REPLY

Please enter your comment!
Please enter your name here