Reputation: 57
Scenario:
But it is not selecting the second option in the loop and giving this error message:
Element is no longer attached to the DOM
Command duration or timeout: 11 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '2.48.2', revision: '41bccdd', time: '2015-10-09 19:59:12'
System info: host: 'Treselle', ip: '192.168.0.123', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.7.0_60'
Session ID: 8b83d2b4-acfd-4bb5-9a07-a4155e98dfc1
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=45.0}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Upvotes: 0
Views: 1081
Reputation: 50819
If the DOM has changed in the first download you need to relocate the dropdown each iteration. You should also wait for the report to appear before looking for the dropdown again
WebDriverWait wait = new WebDriverWait(driver, 20);
int size = 3;
for (int i = 2 ; i < size ; ++i) {
WebElement dropdown = driver.findElement(...);
Select select = new Select(dropdown);
size = select.getOptions().size(); //change the condition to the number of options
select.selectByIndex(i);
driver.findElement(...).click(); //download the report
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ReportViewerControl_AsyncWait_Wait"))); //wait for the loader to appear
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.id("ReportViewerControl_AsyncWait_Wait"))); //wait for the loader to disappear
}
Upvotes: 1