Element is not clickable at point (x,y.5) because another element obscures it
Asked Answered
D

9

21

I am trying to click on an element but getting the error:

Element is not clickable at point (x,y.5)

because another element obscures it.

I have already tried moving to that element first and then clicking and also changing the co-ordinates by minimizing the window and then clicking, but both methods failed. The possible duplicate question has answers which I have already tried and none of them worked for me.

Also, the same code is working on a different PC.

How to resolve it?

Douglass answered 13/3, 2018 at 9:46 Comment(3)
if you watch the test run, can you see what is obscuring it?Erase
Possible duplicate of Element MyElement is not clickable at point (x, y)... Other element would receive the clickAbdication
No, even if another element would obscure it, moving to the element and then clicking should work and also the same code is working on different PC.Douglass
S
18

There is possibly one thing you can do. It is very crude though, I'll admit it straight away.

You can simulate a click on the element directly preceding the element in need, and then simulate a key press tab and enter.


Actually, I've been seeing that error recently. I was using the usual .click() command provided by bare selenium - like driver.find_element_by_xpath(xpath).click().

I've found that using ActionChains solved that problem.

Something like ActionChains(driver).move_to_element(element).click().perform() worked for me.

You will need:

from selenium.webdriver.common.action_chains import ActionChains

Shows answered 13/3, 2018 at 16:25 Comment(4)
I have tried ActionChains already and still got the same error.Douglass
Using keyboard operation( TAB then RETURN) on preceding element, it worked.Douglass
Really nice solution with ActionChainsPrototype
ActionChains is genious! :-)Estray
O
48

This often works when element.click() does not:

element = driver.find_element_by_xpath(xpath)
driver.execute_script("arguments[0].click();", element)
Obscuration answered 29/7, 2020 at 15:49 Comment(1)
Is there a good reason for why this works while .click() fails?Shimmy
S
18

There is possibly one thing you can do. It is very crude though, I'll admit it straight away.

You can simulate a click on the element directly preceding the element in need, and then simulate a key press tab and enter.


Actually, I've been seeing that error recently. I was using the usual .click() command provided by bare selenium - like driver.find_element_by_xpath(xpath).click().

I've found that using ActionChains solved that problem.

Something like ActionChains(driver).move_to_element(element).click().perform() worked for me.

You will need:

from selenium.webdriver.common.action_chains import ActionChains

Shows answered 13/3, 2018 at 16:25 Comment(4)
I have tried ActionChains already and still got the same error.Douglass
Using keyboard operation( TAB then RETURN) on preceding element, it worked.Douglass
Really nice solution with ActionChainsPrototype
ActionChains is genious! :-)Estray
V
1

It was @wrecks idea, but If using php-webdriver you can use below code:

$element = $driver->findElement(WebDriverBy::cssSelector($id_login));
$driver->executeScript("arguments[0].click();", [$element]);
Vaclava answered 22/12, 2020 at 3:31 Comment(0)
R
0

I found that sometimes the webpage is not fully loaded and the answer is as simple as adding a time.sleep(2).

Riesling answered 29/7, 2021 at 10:23 Comment(0)
T
0

If anyone is looking for the Java version of the solution posted by @wrecks here it is:

WebElement element = driver.findElement(By.xpath("//*[@id='element1']"));
((RemoteWebDriver) driver).executeScript("arguments[0].click();", element);
Tiberius answered 3/7, 2022 at 18:36 Comment(0)
L
0

I had the same problem though I'm not in a python environment. In my case it was caused by those annoying Cookie Statement / Warnings that you have to click. The cookie statement / warning was obscuring the element I needed to click. So, the solution for me was to click on the accept button.

I figured that out by watching this video:

https://youtu.be/k6g4MMavM1U

Lightfoot answered 13/12, 2022 at 14:15 Comment(0)
S
0

I had a similar problem. Although it isn't the same as the question problem, it has the same error message in python and maybe helps others with the same problem as me (I'm willing to change this answer into another question if it isn't appropiate here).

A "loading" div with a spinner inside overlays the button I want to click. To solve this I just waited until this "loading" div goes invisible.

Here is a small code example:

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

driver = webdriver.Firefox()
driver.get("url/to/visit")

# do some clicks or actions

# this "wait" can be reused
wait = WebDriverWait(self.driver, timeout=15)

# invisibility check
spinner = driver.find_element(
    By.CSS_SELECTOR, ".spinnercontainer")
wait.until(EC.invisibility_of_element(spinner))

# click button
driver.find_element(
    By.CSS_SELECTOR, ".fa-exchange").click()

Here is the Selenium expected conditions reference for this invisibility check:

selenium.webdriver.support.expected_conditions.invisibility_of_element(element)

An Expectation for checking that an element is either invisible or not present on the DOM. element is either a locator (text) or an WebElement

Before this implementation, I tried to wait until the button was clickable, but it didn't work because those conditions were satisfied regardless of the button being obscured by this spinner.

selenium.webdriver.support.expected_conditions.element_to_be_clickable(mark)

An Expectation for checking an element is visible and enabled such that you can click it. element is either a locator (text) or an WebElement

Senate answered 20/5, 2023 at 4:35 Comment(0)
E
0

This code resolves my problem:

this.driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

IWebElement btnConsulter = driver.FindElement(By.Id("ctl00_contenuPrincipal_btnConsulter"));
this.driver.ExecuteJavaScript("arguments[0].click();", btnConsulter);
        
this.driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
Etch answered 10/7, 2023 at 15:25 Comment(0)
O
0

I had the same error with Watir / Nerodia (high-level library for selenium) and here is a more elegant solution without injecting JavaScript.

My issue was a pop-up was triggered by Jquery / JavaScript when the page load for a user for the first time and was obscuring the link in the menu. So the solution is to close it before clicking the link. But because the pop-up has a fade-in, I have to wait for the pop-up to be visible before closing it and because the pop-up has a fade-out, I have to wait the link is not obscured anymore before clicking it.

So Instead of:

b.link(visible_text: 'Log in').click

I have:

b.button(visible_text: 'Close').wait_until(&:visible?).click
b.link(visible_text: 'Log in').wait_while(&:obscured?).click
Outoftheway answered 14/7, 2023 at 15:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.