【问题标题】:server error 500 when waiting after clicking单击后等待时服务器错误500
【发布时间】:2019-04-01 11:38:23
【问题描述】:

我正在使用 Selenium 为我的 Django 项目测试一个函数。

我有一个可以点击的按钮,经过一些处理后会重定向到另一个页面。

我用来测试它:

@classmethod
def wait_until(cls, findhow, findwhere):
    WebDriverWait(cls.selenium, 10).until(EC.presence_of_element_located((findhow,findwhere)))

所以,我(Selenium)点击按钮,重定向到一个页面,在这个页面上,有一个text_table。此表是我正在检查以检测重定向的元素。

self.wait_until(By.ID, 'text_table')

但我立即(没有任何停顿)得到500 server error,带有回溯:

Traceback (most recent call last):
  File "/mnt/backup/BACKUP_Aubrey/workspace/LingL/functional_tests/selenium_text_detail.py", line 56, in test_create_a_new_text
    self.wait_until(By.ID, 'text_table')
  File "/mnt/backup/BACKUP_Aubrey/workspace/LingL/functional_tests/selenium_base.py", line 53, in wait_until
    EC.presence_of_element_located((findhow,findwhere))
  File "/home/campagne/backup_ln/.Envs/LingL/lib/python3.7/site-packages/selenium/webdriver/support/wait.py", line 80, in until
    raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 

(消息部分为空)

有什么想法吗? 浏览器似乎没有考虑等待时间(10、20 或 30 秒......)并立即重定向。我猜 505 错误是因为重定向是即时的,不允许我在点击事件之后编码的处理(它处理一些由 GET 发送的值)

【问题讨论】:

    标签: selenium selenium-webdriver webdriver webdriverwait


    【解决方案1】:

    根据您尝试调用click() 的问题,因此您需要使用element_to_be_clickable() 而不是使用预期的条件作为presence_of_element_located(),如下所示:

    @classmethod
    def wait_until(cls, findhow, findwhere):
        WebDriverWait(cls.selenium, 10).until(EC.element_to_be_clickable((findhow,findwhere)))
    

    继续,你可以调用click()方法:

    self.wait_until(By.ID, 'text_table')
    

    【讨论】:

    • 它不工作。顺便说一句,重定向页面包含一个text_table,但这个表格不是可点击的元素。它仍然立即加载重定向页面
    • @ThePhi 你为什么要这样做 ...所以,我点击按钮... 如果 ...此表不是可点击元素... .?
    • 我的意思是:我(Selenium)单击按钮,重定向到一个页面,在这个页面上,有一个text_table。此表是我正在检查以检测重定向的元素。
    猜你喜欢
    • 2022-01-20
    • 2020-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-30
    • 1970-01-01
    相关资源
    最近更新 更多