Right now the program says:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="modal-manager"]/div/div/div[2]/button[2]"}
How do I prevent the program from crashing if it doesn't find the element, to cycle over again.
def auto_swipe(self):
x = 0
while x == 0:
sleep(0.5)
try:
dislike_btn = self.driver.find_element_by_xpath('//*[@id="content"]/div/div[1]/div/div/main/div/div[1]/div/div[2]/div[2]/button')
dislike_btn.click()
except Exception:
self.close_popup()
def close_popup(self):
popup_3 = self.driver.find_element_by_xpath('//*[@id="modal-manager"]/div/div/div[2]/button[2]')
popup_3.click()