[英]Inconsistent selenium.common.exceptions.TimeoutException with Python and Selenium
I am getting an inconsistent TimeoutException when running a Selenium script. 运行Selenium脚本时,我收到不一致的TimeoutException。 If I step through the script using the PyCharm debugger, pausing at each line, the script runs successfully (assert passes, no TimeoutException).
如果我使用PyCharm调试器逐步执行脚本,则在每一行暂停,脚本将成功运行(声明传递,没有TimeoutException)。
However, when I run the script normally, I get a TimeoutException every time in the last wait.until(). 但是,当我正常运行脚本时,每次在最后一个wait.until()中都会得到一个TimeoutException。 I have read the documentation on EC.presence_of_element_located and I believe I'm using it correctly.
我已经阅读了EC.presence_of_element_located上的文档,并且相信自己使用正确。 Why am I getting this exception?
为什么我得到这个例外? Here's the code:
这是代码:
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'))
And here's the error: 这是错误:
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:
It would be a guess, but you might need to switch from presence_of_element_located
to element_to_be_clickable
here: 这将是一个猜测,但您可能需要在此处从
presence_of_element_located
为“ 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.