Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Chick if object exists.
#2
(Oct-05-2019, 07:27 PM)Martinelli Wrote: So, does anyone know how can I check if that object exists before try to use it?
You can wrap your code into try/except clause, e.g.
from selenium.common.exceptions import NoSuchElementException
# ... 
try:
    nav.find_element_by_xpath('/html/body/div[1]/div/div[3]/div[1]/div/div[2]/div/div/span[1]/p[1]')
except NoSuchElementException:
    pass # or do something
Reply


Messages In This Thread
Chick if object exists. - by Martinelli - Oct-05-2019, 07:27 PM
RE: Chick if object exists. - by scidam - Oct-06-2019, 05:07 AM
RE: Chick if object exists. - by Martinelli - Oct-06-2019, 08:57 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  ReferenceError: weakly-referenced object no longer exists MrBitPythoner 17 11,686 Dec-14-2020, 07:34 PM
Last Post: buran
  p]Why os.path.exists("abc/d") and os.path.exists("abc/D") treat same rajeev1729 1 2,201 May-27-2020, 08:34 AM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020