在Selenium Python中web抓取元素时超时异常

2024-06-23 19:29:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我在尝试单击下拉链接时遇到超时异常-我已经尝试了在各种论坛上找到的所有解决方案(例如:将等待时间增加到60秒,使用time.sleep,更改定位器) 但这个错误似乎并没有消失

FWIW:我试图点击的页面和链接在1秒钟内加载,所以不确定发生了什么

有人能帮我做点什么吗

代码片段如下所示:

def __init__(self, driver):  # initialize each WebElement here
    self.driver = driver
    wait = WebDriverWait(self.driver.instance, 10)
    self.data_dropdown = wait.until(
        EC.visibility_of_element_located((
            By.XPATH, '//*[@id="ProjectDataTab"]')))  # Data dropdown
    self.view_all_link = wait.until(
        EC.visibility_of_element_located((
            By.LINK_TEXT, 'View All')))  # View All link

错误堆栈跟踪:

ERROR: test_form_case_exports (__main__.TestCCHQ)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:/Users/DSI/PycharmProjects/CCHQ_Smoke/testcases/CCHQ_1.py", line 27, in test_form_case_exports
    form_case_exports = FormCaseExports(self.driver)
  File "C:\Users\DSI\PycharmProjects\CCHQ_Smoke\pageobjects\form_case_exports.py", line 21, in __init__
    By.LINK_TEXT, 'View All')))  # View All link
  File "C:\Users\DSI\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

Tags: selfformviewbydriverlinkallusers

热门问题