How to avoid “StaleElementReferenceException” in Selenium?

前端 未结 16 2378
一向
一向 2020-11-22 12:12

I\'m implementing a lot of Selenium tests using Java. Sometimes, my tests fail due to a StaleElementReferenceException. Could you suggest some approaches to mak

16条回答
  •  梦谈多话
    2020-11-22 12:51

    The problem is by the time you pass the element from Javascript to Java back to Javascript it can have left the DOM.
    Try doing the whole thing in Javascript:

    driver.executeScript("document.querySelector('#my_id').click()") 
    

提交回复
热议问题