UI上的表GUI数据没有更改(经常),但在Python Selenium上仍然得到StaleElementReferenceException

时间:2019-06-23 01:34:34

标签: selenium selenium-webdriver selenium-chromedriver

关于类似问题,我也看到了很多帖子和反馈。但是找不到与我的情况类似的任何线程。

StaleElementReferenceException on Python Selenium

http://allselenium.info/handle-stale-element-reference-exception-python-selenium/

Message: stale element reference: element is not attached to the page document

为使问题更好地理解,我将使用所附的屏幕截图。

从第一张图片开始,     如果您查看遍历(4个级别的GREEN矩形),我正在使用它来达到所需的7行。     到第4级遍历为止,所有操作都可以使用传统的硒python方法。     但是,当我使用第4级对象循环搜索行时,我一直在获取“ StaleElementReferenceException”。     虽然行没有改变。我已经尝试了上述网址中的所有方法。但是他们都没有解决这个问题。

One interesting thing, when I inspect the element using Chrome, and when I click on the tbody tag, I am able to see the rows for 1 to 2 seconds
 and then it closes the tree structure automatically. This happen continuously. 

 I have attached another screenshot where you can see the Tbody node and other 2 nodes gets flicker with PINK color periodically.

 The window open in the first screen is complete static and will not get change unless i do any action on UI. But they are timebound may change after certain period. (minium 30 mins)

 not sure how to handler such situation, because without getting object on the yellow rows,I won't be able to proceed as it has Right click menu option where I have to click.

如果您看到下面的代码,我尝试了try / catch,但它仅在循环的第一次起作用,而在第二次迭代中,我从循环引导,最终从功能引导。

还有一件事,当我进入for循环时,

len(window_rows)返回7行。

    for row_counter in range(len(window_rows)):
        if second_isfound:
            break


        try:
            row_id_text = window_rows[row_counter].get_attribute("id")
        except StaleElementReferenceException as Exception:
            window_rows = window_tbody.find_elements_by_tag_name("tr")
            print('Trying again')
            row_id_text = window_rows[row_counter].get_attribute("id")
            print("hi {}".format(row_id_text))

        print(row_id_text)
        if row_id_text == '1021301171':
            second_isfound = True
            return window_rows[row_counter]

我希望从此for循环中获取匹配的对象。

First Image

second Image

0 个答案:

没有答案