1. 程式人生 > >stale element reference: element is not attached to the page document 錯誤記錄

stale element reference: element is not attached to the page document 錯誤記錄

2018.10.09
今天又跑了一遍,竟然又神器的不報錯了。。。
持續關注這個問題,應該還會再碰到。

2018.10.09pm
刷部落格發現了這個問題的處理方法,問題完美解決。
下面是程式碼修改:
 

在基類中做如下修改

#點選元素
def click(self, selector):
    el = self.find_element(selector)
    try:
        text = el.text
        el.click()
        logger.info("The element \' %s \' was clicked." % text)
        # el.click()
        # logger.info("The element \' %s \' was clicked." % el.text)

    except NameError as e:
        logger.error("Failed to click the element with %s" % e)


這段註釋掉的# el.click() 
           # logger.info("The element \' %s \' was clicked." % el.text)是之前報錯的程式碼。
修改為     text = el.text
           el.click( )
           logger.info("The element \' %s \' was clicked." % text)儲存執行應該問題就解決了