0

I am creating a selenium test with java. I want to automize a dropdown menu in a dialogue. The xpath of the dropdown menu is:

/html/body/div[8]/div/div/form/div[2]/div[2]/div[2]/div/select

My problem is that I cant select an element from the dropdown menu. I used:

new WebDriverWait(driver, 20).until

and ExpectedCondition to select an element. Can you help me to find a way to select an element from the drop-down.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
tobias
  • 63
  • 2
  • 8

2 Answers2

0

You need to first click the dropdown button and then find the the button you want to select from the dropdown and then click on it.

yashetty29
  • 43
  • 1
  • 7
0

To select one of the from a tag you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • Using id and selectByIndex():

    new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("selectID")))).selectByIndex(1);
    
  • Using cssSelector and selectByVisibleText():

    new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("selectCssSelector")))).selectByVisibleText("OptionText");
    
  • Using xpath and selectByValue():

    new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("selectXpath")))).selectByValue("OptionValue");
    

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352