Selenium: Is there a way to force click an element when another element obscures it?


I am currently running in headless mode (uploaded in CirclCI Docker) and the site I am working on has an Accept Cookies banner. Apparently, in headless mode, it obscures the Log In button I need to click to be able to proceed with my test. Is there a way to disable checking?

We have .click({force: true}) in Cypress. Do we have a counterpart in Selenium?

Website is


Before going it Mailtrap, I came from another origin. I tried to use the Options() for Firefox before visiting Mailtrap but it doesn’t work. If I put it at the first run, it messes up with the other site as well.

Here is the code:

options = Options()
options.set_preference("network.cookie.cookieBehavior", 2)
loginButton = context.mailTrapPage.getLoginButton()
context.driver.execute_script("arguments[0].click();", loginButton)

Here is the error I’m getting:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a class="login_next_button button button--medium button--block" href="#"> is not clickable at point (388,614) because another element <p class="cookies-banner__text"> obscures it
      [email protected]://remote/content/shared/RemoteError.jsm:12:1
      [email protected]://remote/content/shared/webdriver/Errors.jsm:192:5
      [email protected]://remote/content/shared/webdriver/Errors.jsm:291:5
      [email protected]://remote/content/marionette/interaction.js:166:11
      [email protected]://remote/content/marionette/interaction.js:125:11
      [email protected]://remote/content/marionette/actors/MarionetteCommandsChild.jsm:204:29
      [email protected]://remote/content/marionette/actors/MarionetteCommandsChild.jsm:92:31
Asked By: Faith Berroya



Yes, you can click any existing element, including covered by other element, with JavaScript click as following:

element = driver.find_element(By.XPATH, element_xpath_locator)
driver.execute_script("arguments[0].click();", element)

However you need to remember that Selenium is developed to imitate actions performed by human user via GUI and human user can not perform such actions. As a user you will have to scroll the page or open dropdown etc. to make that element accessible and only then click it. But if sometimes you just need to perform some action without caring if such action can be done by a human user – you can use JavaScript clicks and other methods, out of Selenium covered actions.
You specific problem caused by selecting a wrong element.
The following code works for me:

from selenium import webdriver
from import Service
from import Options
from import WebDriverWait
from import By
from import expected_conditions as EC

options = Options()

webdriver_service = Service('C:webdriverschromedriver.exe')
driver = webdriver.Chrome(service=webdriver_service, options=options)
url = ''
wait = WebDriverWait(driver, 20)

wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#signinTopBlock a[href*='signin']"))).click()
Answered By: Prophet