I have a form that has 4 dropdowns. Based on first dropdown selection , second dropdown list is populated and based on second drop down selection third dropdown list is populated and based on third selection fourth drop down list is populated.
1.Department
2.Country
3.Language
4.Reason
I have created a method using fluent waits giving the drop down time to load based on prior selections. But below method still fails on StaleElementReferenceException. To verify if it is timing issue, i placed Thread.sleep(200) instead of fluent waits and the test is successful.
Please help me in understand how to avoid hard waits to handle this situation.
My test runs on Windows 7 and IE11 browser.
public void submit()
{
Wait<WebDriver> wait1 = new FluentWait<WebDriver>(driver)
.withTimeout(shortTimeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollTimeInSeconds, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
wait.until(ExpectedConditions.elementToBeClickable(Department));
Department.click();
new Select(Department).selectByIndex(1);
Wait<WebDriver> wait2 = new FluentWait<WebDriver>(driver)
.withTimeout(shortTimeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollTimeInSeconds, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
wait.until(ExpectedConditions.elementToBeClickable(Country));
Country.click();
new Select(Country).selectByIndex(1);
Wait<WebDriver> wait3 = new FluentWait<WebDriver>(driver)
.withTimeout(shortTimeoutInSeconds, TimeUnit.SECONDS)
.pollingEvery(pollTimeInSeconds, TimeUnit.SECONDS)
.ignoring(NoSuchElementException.class)
.ignoring(StaleElementReferenceException.class);
wait.until(ExpectedConditions.elementToBeClickable(Language));
Language.click();
new Select(Language).selectByIndex(1);
}