How to handle drop down field data which comes from database using selenium. A form contains 2 drop down fields and one is having HTML data and it is handled perfectly. Data to the 2nd drop down comes as per the selection from the 1st which comes from database. Need guides to complete the action.
Asked
Active
Viewed 84 times
1 Answers
0
To select from two html-select fields where the data which comes from database using Selenium induce WebDriverWait for the elementToBeClickable()
and you can use either of the following java based Locator Strategies:
Using cssSelector and
selectByVisibleText()
:new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("cssFirstSelectElement")))).selectByVisibleText("firstSelectOptionText"); new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("cssSecondSelectElement")))).selectByVisibleText("secondSelectOptionText");
Using xpath and
selectByValue()
:new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("xpathFirstSelectElement")))).selectByValue("firstSelectOptionValue"); new Select(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("xpathSecondSelectElement")))).selectByValue("secondSelectOptionValue");
References
You can find a couple of relevant detailed discussions in:

undetected Selenium
- 183,867
- 41
- 278
- 352