How to Select an Item from a Dropdown List Using Selenium Webdriver with Java

How to select an item from the dropdown list through selenium webdriver and java

So, I was able to click on the first option getting the XPath from this element:

driver.findElement(By.xpath("//ul[contains(@class,'scrollable')]")).click();

However, this isn't very dynamic as I am unable to click on the second option.

Select from dropdown in selenium-webdriver javascript

In selenium-webdriver JavaScript you don't have "Select" class. You just need to simply click on drop-down option by passing correct css/xpath.

let element = driver.wait(until.elementLocated(By.css(cssLocator)));
element.click();

Selenium - Selecting an item from dropdown list if the values are inside table tags and NOT under option in html

It appears that since the drop down options were inside a < table >, the Select class was unable to identify the list options. So here's what I did:

First click() the dropdown, which opens up the menu:

driver.findElement(By.xpath(".//*[@id='abc01_tbl']/div/div")).click();

Then pass the value using the contains() method and then click() on it.

driver.findElement(By.xpath(".//*[@id='xyz01_tbl']/tbody/tr/td[1][contains(text(),'I am option2')]")).click();


Related Topics



Leave a reply



Submit