How to resolve, Stale element exception? if element is no longer attached to the DOM?

后端 未结 7 1198
盖世英雄少女心
盖世英雄少女心 2020-11-30 23:01

I have a question regarding \"Element is no longer attached to the DOM\".

I tried different solutions but they are working intermittent. Please suggest a solution th

7条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 23:14

    https://www.swtestacademy.com/selenium-wait-javascript-angular-ajax/ here is a good article about dynamic waiter strategies. Your problem is not waiting properly all the ajax, jquery or angular calls. Then you end up with StaleElementException.

    If your approach is to use Try-Catch mechanism, I guess it has a flaw. You shouldn't rely on that structure as you'll never know it's gonna work in the catch clause.

    Selenium gives you the opportunity to make javascript calls. You can execute

    • "return jQuery.active==0"
    • return angular.element(document).injector().get('$http').pendingRequests.length === 0"
    • "return document.readyState"
    • "return angular.element(document).injector() === undefined"

    commands just to check the existence and states of those calls.

    You can do that before any findBy operation so you always work with the latest page

提交回复
热议问题