Silver Silver - 3 months ago 85
Javascript Question

"Element is not clickable at point (x,y)". Invisible element covers the button

I’m stuck trying to get Selenium with Chrome Webdriver to click a buttom, but there is an element

<div class="modal-overlay" style="display: block;"></div>
that covers the entire page and is invisble, that is blocking my clicks. How can I work around this?

I tried using this:

element = driver.find_element_by_xpath("//input[@type='submit']")
driver.execute_script("arguments[0].click();", element)


but it didn’t work. What can I do in this situation?
EDIT:
I used luke_aus answer and got this from the page: (third last image)

http://imgur.com/a/MlmpK

Answer

In your case you need to make overlay element invisible forcefully before going to click on submit button as below :-

#first make overlay element invisible 
overlay = driver.find_element_by_css_selector("div.modal-overlay")
driver.execute_script("arguments[0].style.display = 'none'", overlay)

#now find submit button and click 
driver.find_element_by_id("DeleteSurveyO‌​K").click()

Edited1 :- If still it throws exception that submit button is invisible, you should try using WebDriverWait to wait until submit button visible after overlay element invisible as below :

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

#first make overlay element invisible 
overlay = driver.find_element_by_css_selector("div.modal-overlay")
driver.execute_script("arguments[0].style.display = 'none'", overlay)

#now find submit button and click 
button = WebDriverWait(driver, 10).until(
EC.visibility_of_element_located((By.ID, "DeleteSurveyO‌​K")))
button.click()

Edited2 :- If unfortunately submit button is not getting visible try to submit form instead of clicking submit button as below :-

#first make overlay element invisible 
overlay = driver.find_element_by_css_selector("div.modal-overlay")
driver.execute_script("arguments[0].style.display = 'none'", overlay)

#now submit the form 
driver.find_element‌​_by_id("ModelSurveyFo‌​rm").submit()