Answer the question
In order to leave comments, you need to log in
How to check if an element exists on a page using python+selenium?
I go to a page where there can be either a sign with different options or an input field and a confirm button. If there is no input field - I want to be able not to run into a traceback that they say
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element:
. Answer the question
In order to leave comments, you need to log in
from selenium.common.exceptions import NoSuchElementException
try:
do something with the element
except NoSuchElementException:
do something else
This scheme works for me.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question