我使用Python的Selenium webdriver打印內容的一個元素,但如果它不存在於頁面上,它會破壞我的代碼並返回一個異常錯誤。Selenium Webdriver NoSuchElementException
print (driver.find_element_by_id("TotalCost").text)
NoSuchElementException: Message: no such element: Unable to locate element
{"method":"id","selector":"TotalCost"}
我可以做些什麼來解決這個錯誤?
你能趕上('除了NoSuchElementException異常如前:')這個異常。 –
我在打印聲明後的位置? (除了NoSuchElementException除外:) – 7O07Y7
閱讀關於[例外](https://docs.python.org/3.5/tutorial/errors.html) –