Getting StaleElementReferenceException while trying print the link names

前端 未结 3 1504
臣服心动
臣服心动 2020-12-02 02:28

I\'m trying to print first 5 pages links displayed in google search.. But getting StateElementReferenceException Not sure which one went wrong..

    public          


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-02 03:35

    your script is trying to click on each link from the first page, which brings you to a new page. once it completes work on that page, it doesn't seem to return to the first page, so the script can't find the next link in your list.

    even if it did return to the first page, you would still have a stale element because the page has been reloaded. You'll need to keep track of the links in the first page by something else (like the href maybe?), and find the link again by that identifier before you click on it.

提交回复
热议问题