运行Selenium脚本时出现不一致的TimeoutException。如果我使用PyCharm调试器逐步执行脚本,在每行暂停,脚本成功运行(断言传递,没有TimeoutException)。
但是,当我正常运行脚本时,每次在最后一次wait.until()中都会收到TimeoutException。我已阅读有关EC.presence_of_element_located的文档,我相信我正确使用它。为什么我得到这个例外?这是代码:
def test_if_special_diet_types_are_correct(self):
wait = WebDriverWait(self.driver, 10)
utils = Utils(self.driver, wait, self)
utils.login()
tab = self.driver.find_element_by_id("clients-tab")
tab.click()
list_item = wait.until(EC.presence_of_element_located((By.ID, '66')))
list_item.click()
edit_button = wait.until(EC.presence_of_element_located((By.ID, 'edit-client-button')))
edit_button.click()
element = wait.until(EC.presence_of_element_located((By.ID, 'client-input-first-name')))
self.assertEqual('John', element.get_attribute('value'))
这是错误:
Error
Traceback (most recent call last):
File "/Users/jcleveland/projects/zippymeals/browser_tests/account.py", line 54, in test_if_special_diet_types_are_correct
EC.presence_of_element_located((By.ID, 'client-input-first-name')))
File "/Users/jcleveland/projects/zippymeals/env/lib/python3.4/site-packages/selenium/webdriver/support/wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
答案 0 :(得分:0)
这是猜测,但您可能需要在此处从presence_of_element_located
切换到element_to_be_clickable
:
list_item = wait.until(EC.element_to_be_clickable((By.ID, '66')))
list_item.click()
edit_button = wait.until(EC.element_to_be_clickable((By.ID, 'edit-client-button')))
edit_button.click()