python+selenium報錯:ElementNotVisibleException: Message: element not interactable


錯誤提示:
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable
錯誤原因:
可能是因為動態加載過程中,未加載出對應元素從而無法觸發到該操作
解決方案:
增加循環判斷元素是否加載完成再執行腳本:
def click_element(self,type,locator,timeout=5):
    max_time = time.time() + timeout
    while time.time() < max_time:
        if self.driver.find_element(type,locator):
            self.driver.find_element(type,locator).click()
            break
        time.sleep(0.2)
    else:
        print('locator %s not found' % locator)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM