how to avoid stale element exception

List<WebElement> listof items= testDriver.findElements(By.cssSelector(“css_path”))

Default Asked on November 25, 2014 in Selenium WebDriver.

Hi Shubha

Do you mind posting your code here ?

on November 26, 2014.
Add Comment
  • 3 Answer(s)


    I am not sure what exactly you are trying to do.

    This exception occur when we try to do some action on element which is refreshed and as a result driver can’t recognise that element anymore.

    I would suggest to capture the element again during runtime.

    I faced this exception when I was working on DatePicker.

    Train Answered on November 26, 2014.

    Ranjodh is right.

    on November 26, 2014.
    Add Comment

    Hi Shubha

    Stale Element Exception can be Avoided by putting Proper wait After the Line That is Causing Javascript Action
    Make Sure that Complete Javascript have been Performed Before You TryIng Action on some Element


    Vice Professor Answered on November 25, 2014.
    Add Comment

    Hi Ankit,
    Yes agreed, I tried putting a wait time of around 2 mins, but dint help out,
    In my case here, after a specific text is found & action is performed that specific item is removed from the current page & the count of “listof items” is -1.

    could you please suggest on this.

    Default Answered on November 25, 2014.

    What Exactly are you doing with that List..?

    on November 25, 2014.
    Add Comment
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.