单击后等待服务器错误500

时间:2018-10-28 09:56:02

标签: selenium selenium-webdriver webdriver webdriverwait

我正在用Selenium测试我的Django项目的功能。

经过一些处理后,我需要单击一个按钮,该按钮将重定向到另一个页面。

我用来测试它:

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

因此,我(硒)单击按钮,该按钮重定向到页面,在此页面上,有一个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发送的某些值)

1 个答案:

答案 0 :(得分:0)

根据您要尝试调用click()的问题,因此,除了使用Expected_conditions作为presence_of_element_located()之外,还需要使用element_to_be_clickable(),如下所示:

@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')