简体   繁体   中英

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..

码

HTML Block:

HTML块

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

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

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