Skip to content Skip to sidebar Skip to footer

How To Select A Combobox Value With Selenium Webdriver Where It's A Div With Role Of Combobox

My HTML code has a div tag with the role as combobox, i.e.
...
I am trying to select an item from the combo box through selenium driver

Solution 1:

As there is no

select html tag

in your html code,

"Select"classwillnot work here.

So u can do this in two ways(As u don't give ur details html code)

First process:

Step one: click on that combo box.

Step two: After click on combo box, combo box options will be shown with their link text or id or other locators.

for this, use this code:

driver.findElement(By.id("search_key.combobox")).click();//click on that combo

than

driver.findElement(By.linkText("ur combo option link text"));//click on ur desired combo optionor
driver.findElement(By.cssSelector("ur combo option's css path"));//u can use any other locator what is shown in ur html code after clicking on combo box

But after click on combo box, if combo options is not shown with any locator in inspect section, than use this code:

driver.findElement(By.id("search_key.combobox")).click();//click on that combofor(inti=0; i <= position; i++){
    Actionsactions=newActions(driver);
    actions.sendKeys(Keys.DOWN).build().perform();//press down arrow keyActionsactions=newActions(driver);
    actions.sendKeys(Keys.ENTER).build().perform();//press enter
}

//here "position" is , ur desired combo box option position,//for ex. u want to choose 3rd option,so ur "position" will be 3.

Solution 2:

Did you tried with Sendkeys()?

driver.findElement(By.xpath("//div[@role='combox']")).sendKeys("text to select exp: selenium");

if above does not works as expected, you can try with click on drop down and click on required option in that drop down.

Thanks

Solution 3:

I was able to solve this by first clicking on the div , which displayed all the options and then clicking on the required option.

Thank you to all of you for your suggestions.

Post a Comment for "How To Select A Combobox Value With Selenium Webdriver Where It's A Div With Role Of Combobox"