2

I want to click on a button that is either not yet clickable or has another element on top of it.

But as soon as it is clickable, I want to press it. I tried this:

button = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CLASS_NAME, "likeClick")))
button.click()

But it doesnt work because I still get the error

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a class="likeClick"> is not clickable at point (400,553) because another element <div class="delete-overlay"> obscures it```
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
badg
  • 73
  • 1
  • 2
  • 6
  • Does this answer your question? [Selenium-Debugging: Element is not clickable at point (X,Y)](https://stackoverflow.com/questions/37879010/selenium-debugging-element-is-not-clickable-at-point-x-y) – Prophet Mar 13 '22 at 16:09
  • @Prophet It shouldn't as this usecase is _ElementClickInterceptedException_ where as the dup target is about _WebDriverException_. – undetected Selenium Mar 13 '22 at 17:19

1 Answers1

3

This error message...

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a class="likeClick"> is not clickable at point (400,553) because another element <div class="delete-overlay"> obscures it

...implies that the click to the <a> element failed as the element was obscured the <div> element which seems to be an temporary overlay .


Solution

To click on the desired element you need to induce WebDriverWait for the invisibility_of_element_located() of the overlay and then induce WebDriverWait for the element_to_be_clickable() and you can use either of the following locator strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 30).until(EC.invisibility_of_element_located((By.CSS_SELECTOR, "div.delete-overlay")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.likeClick"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 30).until(EC.invisibility_of_element_located((By.XPATH, "//div[@class='delete-overlay']")))
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[@class='likeClick']"))).click()
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352