Selenium Python Element Click Intercepted

Question:

I’m trying to run a test in Selenium Webdriver Python, but I got an error saying as on the screenshot:

enter image description here

this is the xpath for the register button: //button[@class='tutor-btn tutor-btn-primary']

What I tried so far:

setup.find_element("xpath", "//button[@class='tutor-btn tutor-btn-primary']").click()

and

setup.find_element("xpath", "//button[@type='submit' and (contains(@class,'tutor-btn tutor-btn-primary')) and(contains(text(),'Register'))]").click()

but none works, any solution?

Asked By: jyra

||

Answers:

This might work,

from selenium.webdriver.common.by import By

setup.find_element(By.CSS_SELECTOR, 'button.tutor-btn.tutor-btn-primary').click()

[update]

Here is another unique way where you don’t even need to click on the "Accept All" button.

driver.get("https://langsungkerja.id/registration/")

driver.add_cookie({"name": "cookieyes-consent", "value": "consent:yes,action:yes"})
driver.refresh()

driver.find_element(By.CSS_SELECTOR, 'button.tutor-btn.tutor-btn-primary').click()
time.sleep(1)

I hope you’ll like it

Answered By: Ajeet Verma

try this function, it needs to get element object.

def click_element(self, element):
    self.driver.execute_script("arguments[0].click();", element)
Answered By: piscoony

Element click intercepted indicates that some other element is obstructing selenium to perform the click() on the desired element.

And that obstructing element is Accept Cookies window.

enter image description here

As soon as you open the application, just add below line and get rid of the cookies window. It should be fine:

driver.get("https://langsungkerja.id/registration/")
driver.maximize_window()
# below line will accept cookies
driver.find_element(By.XPATH, "//button[text()='Accept All']").click()
Answered By: Shawn

First step here is to check if the element you’re trying to click is overlayed by anything. Especially labels love to cover buttons/radios. In that case you need to click the label instead of the button/radio/etc.

While generally not recommended for testing purposes it’s absolutely legit for automation purposes to circumvent things that would block a click through javascript or jquery scripts.

One such example was already posted by piscoony, another one would be something like:

def click_js(driver, dom_class):
    driver.execute_script("$('#" + str(dom_class) + "').click()")

However, i do not see any labels or other obvious elements overlaying the button. Could you please post what element would block the click? It’s cut off in the screenshot.

Something you might also try is look for temporary overlays. I run into seethrough overlays blocking elements while f.e. ajax is active occasionally, i can only guess what those are used for, they seem janky but occur here and there. They often trigger this error for me is to check if those are active with something like

def visibility_check(driver, dom_class):
    driver.execute_script("return $('." + dom_class + ":visible').length")
Answered By: Knolfuns