I am trying to check the existence of two elements(A,B) on a website.What I need is to click on the element A if it exists if not go ahead and look for B and click on it if it exists. Below is part of my sample code.
try:
abc= WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#rso > div > div > div:nth-child(1) > div > div > h3 > a")))
except NoSuchElementException:
continue
except TimeoutException:
continue
else:
element.click()
try:
element = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#rso > div > div > div:nth-child(1) > div > div > h3 > a")))
except NoSuchElementException:
continue
except TimeoutException:
continue
else:
abc.click()
time.sleep(randint(1, 15))
print('Process completed successfully')
The issue that I face is that the code only looks for the first element and doesn't go ahead into the next try. Any advice would be great.