简体   繁体   中英

Selenium, select value from listbox without using select in Java

How to select a value from dropdown?

My solution is not working:

Select dropdown_month = new Select(
    driver.findElement(By.xpath(".//*[@id='BirthMonth']/div[1]/div[2]"))
);
dropdown_month.selectByVisibleText("July");

This is because you're trying to handle <div> element while Select class should be used only with <select> elements.

In your case you might need to use simple click() method as below:

driver.findElement(By.xpath(".//*[@id='BirthMonth']/div[1]/div[2]")).click() // To open drop-down
driver.findElement(By.xpath(".//*[.='July']")).click() // To select required option

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM