lundi 30 novembre 2020

how to solve Stale Element Reference Exception For this scenario in selenium webdriver java?

I tried all ways that I know in selenium web driver but I could not resolve the issue Stale Element Reference Exception. I tried implicit wait, explicit wait, fluent wait in selenium web driver, but I couldn't resolve this issue.

HTML Code is:: I have to click all li options in this list. if I loop this using both foreach, for, or Iterator I can click the first option, for the second option, it Throws an error as Stale Element Reference Exception.

My selenium code is:

List chapterNames = driver.findElements(By.xpath("//[@id='ctl00_PageContent_ddlreviewCat_DropDown']/child::div/ul/li")); //List chapterQues = driver.findElements(By.xpath("//[@id='ctl00_PageContent_grdReviewDocDetailList_ctl00']/child::tbody/tr/td1")); WebElement ChapterNamedrpdwn = driver.findElement(By.id("ctl00_PageContent_ddlreviewCat_Input")); Thread.sleep(2000); for (int i = 0; i < chapterNames.size(); i++) { try { wait=new WebDriverWait(driver,30); ChapterNamedrpdwn.click(); wait.until(ExpectedConditions.refreshed(ExpectedConditions.visibilityOfAllElements(chapterNames))); chapterNames.get(i).click(); System.out.println(chapterNames.get(i).getAttribute("innerHTML")+ " clicked.."); Thread.sleep(3000); } catch(Exception e) { System.out.println(e.getMessage()); } }

Error Message is: stale element reference: element is not attached to the page document (Session info: chrome=86.0.4240.198) For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html

Aucun commentaire:

Enregistrer un commentaire