Automation testing



  • 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]
    


  • 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.


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2