Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting an item from a combo box selenium driver with java

Tags:

java

selenium

I tried to select an item from a combo box through selenium driver with java, but it didn't work.

This is my code...

combo box list = {NIC, NAME, AGE};

driver.findElement(By.xpath("//div[@id='views/div/select']/label")).sendKeys("NIC");
like image 414
Eshan Liyanagama Avatar asked May 02 '26 17:05

Eshan Liyanagama


1 Answers

In WebDriver there is separate Class (Select) is there to deal with Combo lists.

Use below logic to select options from pick list fields

Select select=new Select(driver.findElement(By.xpath("//div[@id='views/div/select']"));

select.selectByVisibleText("NIC");
or
select.selectByIndex(0);
or
select.selectByValue("value");

Refer this post for more info regarding Select class.

like image 149
Santoshsarma Avatar answered May 04 '26 06:05

Santoshsarma