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```
2

1 Answer 1

4

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
    
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.