Swa
Swa

Reputation: 193

Unable to select ajax dropdown value using selenium webdriver

I am trying to select a particular values from 2 Ajax drop down fields.First drop down option list getting open but doesn't select option, that's why second drop down list is not binding and error occurred as

org.openqa.selenium.NoSuchElementException: Unable to locate element: option[value="111"].

Please help me.. I am new on selenium

Here is my code..

Code

HTML Block:

HTML block

Upvotes: 4

Views: 1145

Answers (2)

Swa
Swa

Reputation: 193

This issue occurred because of Firefox browser(version 45) compatibility issue. I am using selenium 3.0.0-beta2 and test against Firefox 45.0.2

When tried geckodriver (version 0.10.0)for OS windows 10 -64 bit, it seems something not work. It only works with Firefox 48 or onwards. It successfully working on chromedriver

Upvotes: 3

Ricardo Vila
Ricardo Vila

Reputation: 1632

You can try a more specific way to interact with dropdowns in selenium. Try something like this:

Select dropdown = new Select(driver.findElement(By.id("cmbJob")));
dropdown.selectByValue("111");

You can even define a function for working with dropdwns:

protected void chooseOptionInSelectByValue(String selectId, String valueString) {
  Select dropdown = new Select(driver.findElement(By.id(selectId)));
  dropdown.selectByValue(valueString);
}

So you can use the function like this

chooseOptionInSelectByValue("cmbJob","111");

Selenium dropdown object has many other options like selectByText, etc. Check it in the API here: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/Select.html

Upvotes: 0

Related Questions