2017-08-31 55 views
-1

如何處理元素丟失時的異常。是否有辦法通過回溯發現什麼是NoSuchElementException的異常錯誤

Traceback (most recent call last): File "firsttry.py", line 56, in < module >

browser.find_element_by_xpath("html/body/div/section/div[1]/div[2]/ul[5]/li/div[1]/form/input[3]").click()

File "C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\webelement.py", line 72, in click self._execute(Command.CLICK_ELEMENT)

File "C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\webelement.py", line 461, in _execute return self._parent.execute(command, params)

File "C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute self.error_handler.check_response(response)

File "C:\ProgramData\Anaconda2\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: unknown error: Element is not clickable at point (659, 28). Other element would receive the click: ... (Session info: chrome=60.0.3112.113) (Driver info: chromedriver=2.24.417431 (9aea000394714d2fbb20850021f6204f2256b9cf),platform=Windows NT 10.0.14393 x86_64)

+1

爲什麼要處理'NoSuchElementException'?考慮到你提供的日誌'元素不可點擊點...'異常 – Andersson

+0

您正在看到'WebDriverException:消息:未知錯誤:元素在點(659,28)處不可點擊。其他元素會收到點擊:...'檢查此[**討論**](https://stackoverflow.com/questions/44912203/selenium-web-driver-java-element-is-not-clickable-at - 點-36-72-其他-EL) – DebanjanB

回答

0

一切都從錯誤消息中清楚。如果某些其他元素正在點擊要單擊的元素,您將無法手動執行相同的操作。

Element is not clickable at point (659, 28). Other element would receive the click:

哪個元素不可點擊?

browser.find_element_by_xpath("html/body/div/section/div[1]/div[2]/ul[5]/li/div[1]/form/input[3]").click()

哪些因素產生的問題? 將斷點放在上面的行並調試代碼。你應該能夠手動看到它。 如果你在失敗時截圖,你可能甚至不需要調試。截圖將足以告訴你。

0

我能夠通過導入異常來捕獲錯誤。此追溯的錯誤將是NoSuchElementException本身。我剛剛從selenium.common.exceptions導入,導入NoSuchElementException

相關問題