Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. QA Testing
  3. Question
QA Testing

How can I resolve this error- stale element reference: element is not attached to the page document

Asked by Sumiko Lacoste Oct 20, 2022 1.1K views 1 answer
Share

About this question

 I am automating my current project. I am trying to click on the main menu.

For that below is my code

WebElement ul = driver.findElementByXPath(prop.getProperty("category"));
    List options = ul.findElements(By.tagName("li"));
    for(WebElement sample: options)
    {
        if(sample.getText().equals(data)){
            sample.click();
        }
    }

When I run this code the main menu is getting clicked and it gets loaded but still I am getting Stale Element reference error exception. Help me to resolve this.

Error:

Exception in thread "main" 

org.openqa.selenium.StaleElementReferenceException: stale element 

reference: element is not attached to the page document


Your answer

1 Answer

More QA Testing discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest QA Testing Blogs

Guides, tips and career advice on QA Testing from JanBask experts.