Check if element exists python selenium -


i'm trying locate element

element=driver.find_element_by_partial_link_text("text") 

in python selenium , element not exist. there quick line check if exists , null or false in place of error message when doesn't exist?

you can implement try/except block below check whether element present or not:

from selenium.common.exceptions import nosuchelementexception  try:     element=driver.find_element_by_partial_link_text("text") except nosuchelementexception:     print("no element found") 

or check same 1 of find_elements_...() methods. should return empty list or list of elements matched passed selector, no exception in case no elements found:

elements=driver.find_elements_by_partial_link_text("text") if not elements:     print("no element found")   else:     element = elements[0]   

Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -