我正在嘗試撰寫一個代碼來檢查網站是否具有拖放功能。為此,我首先檢索網站的所有元素并嘗試通過拖放上傳檔案。但是,當我獲得無效的拖放 ID 時,我收到了一個selenium.common.exceptions.WebDriverException: Message: <unknown>: Element not interactablet例外。我試圖用 try/catch 塊解決它,但它仍然不起作用。
ids = driver.find_elements_by_xpath('//*[@id]')
counter = 0
for ii in ids:
print(ii,ii.get_attribute('id'))
driver.find_element_by_id(ii.get_attribute('id'))
dropzone = driver.find_element_by_id(ii.get_attribute('id'))
try:
dropzone.drop_files("/temp/pythonSelenium/test.txt")
except ElementNotInteractableException:
continue
uj5u.com熱心網友回復:
您可能發現了錯誤的錯誤。錯誤訊息說:
selenium.common.exceptions.WebDriverException: Message: <unknown>: Element not interactable
如您所見,錯誤訊息來源是WebDriverException而不是ElementNotInteractableException。這有點令人困惑,但是如果您想捕獲錯誤,則必須尋找源。
因此,為了捕獲錯誤,您必須將代碼更改為:
try:
dropzone.drop_files("/temp/pythonSelenium/test.txt")
except WebDriverException:
continue
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/339305.html
上一篇:賽普拉斯上傳
