0

I have a situation where I had to handle drop down and click the drop down to select some values. There are two drop down in same page and one from the next page total three drop downs, they 3 have the same xpath. The xpath is giving below.

/html/body/div[2]/div/div[1]/div/div/div[1]/div/div/div[3]/div[2]/div/div/div[1]
/html/body/div[2]/div/div[1]/div/div/div[1]/div/div/div[4]/div/div/div/div[1]
//*[@id="main-panel"]/div/div/div/div[1]/div/div/div/div[1]
  • 1
    The Xpaths are not the same. Please explain better what is the problem. And add the HTML of the page. – Mate Mrše Jul 24 at 13:21
1

Selenium provides a wrapper class to work with dropdowns - Select:

WebElement dropdownElement = driver.findElement(By.id("myDropdown"));
Select dropdown = new Select(dropdownElement);

And you can select things by text or position:

dropdown.selectByVisibleText("Option 1");
dropdown.selectByIndex(0);

You can find more info on this class here.

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.