亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

通過 Selenium 和 Python 使用帶有 expected_conditions

通過 Selenium 和 Python 使用帶有 expected_conditions

慕姐8265434 2023-03-22 16:43:35
Traceback (most recent call last):  File "Inventorytest.py", line 88, in <module>    j.go_to_application()  File "Inventorytest.py", line 65, in go_to_application    EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))  File "/home/naroladev/Mercury_Back-End/mercuryenv/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until    raise TimeoutException(message, screen, stacktrace)selenium.common.exceptions.TimeoutException: Message: 我在 EC2 服務器實例上遇到了異常。我的腳本在 Ubuntu 和 Mac OS 以及本地系統上任何版本的 firefox 和 geckodriver 上都可以正常工作。但是在 EC2 ubuntu 18.04.01 版本上遇到了上述錯誤,在此我也嘗試升級和降級 firefox 和 geckodriver 版本但仍然無法正常工作。誰能幫我提出建議和解決方案。
查看完整描述

1 回答

?
慕尼黑5688855

TA貢獻1848條經驗 獲得超2個贊

這個錯誤信息...


Traceback (most recent call last):

? File "Inventorytest.py", line 88, in <module>

? ? j.go_to_application()

? File "Inventorytest.py", line 65, in go_to_application

? ? EC.element_to_be_clickable((By.ID, 'FavoriteApp_ITEM'))

? File "/home/naroladev/Mercury_Back-End/mercuryenv/lib/python3.6/site-packages/selenium/webdriver/support/wait.py", line 80, in until

? ? raise TimeoutException(message, screen, stacktrace)

selenium.common.exceptions.TimeoutException: Message:?

...意味著WebDriver變體無法在構建WebDriverWait的時間范圍內找到所需的WebElement 。


WebDriver等待

WebDriverWait構造函數將WebDriver實例作為參數和超時(以秒為單位)。

因此,無論使用哪一個expected_conditions,WebDriverWait失敗都會導致TimeoutException。


這個用例

在這個用例中,行:

EC.element_to_be_clickable((By.ID,?'FavoriteApp_ITEM'))

無法在所需的時間范圍內識別所需的元素,因此您遇到了TimeoutException

然而,從TimeoutException中很難挖掘出失敗的實際結果。


解決方案

作為了解失敗確切原因的解決方案,您需要刪除 WebDriverWait并將代碼行替換為:

  • find_element_by_class_name(name)

  • find_element_by_css_selector(css_selector)

  • find_element_by_id(id)

  • find_element_by_link_text(link_text)

  • find_element_by_name(name)

  • find_element_by_partial_link_text(partial_link_text)

  • find_element_by_tag_name(tag_name)

  • find_element_by_xpath(xpath)

如果需要,您可以在調試時減慢搜索誘導等待的速度time.sleep(secs)。


查看完整回答
反對 回復 2023-03-22
  • 1 回答
  • 0 關注
  • 135 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號