I have a button search, and it will show "No results found" or "another button for buy".
What I'm trying to do is to create an if
to check if there is on page "No results found", click on the back button. If not, click on the buy button.
Here is HTML code:
<button> Search </button>
..
<div class="contents"> <h2>No results found<h/2> </div> #the message I want to check first
..
<button class="btn-standard> Buy Now </button> #buy button
...
<button class="back"> Back </button> #the button I want to click if no resul
And I have tried something like below:
if driver.find_element_by_xpath('//h2[text()="No results found"]'):
driver.find_element_by_class_name('back').click()
else:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[contains(., 'Buy Now')]"))).click()
But it didn't work. Do I have to use try / catch
codition?
ANOTHER EDIT:
I got this error now. I have no idea how to hide that element which obscure my Buy button.
ElementClickInterceptedException: Message: Element <button class="btn-standard buyButton"> is not clickable at point (1086,641) because another element <div class="ut-click-shield showing interaction"> obscures it