18

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?

Shubham srivastava
  • 227
  • 1
  • 4
  • 12
  • if you watch the test run, can you see what is obscuring it? – Breaks Software Mar 13 '18 at 11:22
  • Possible duplicate of [Element MyElement is not clickable at point (x, y)... Other element would receive the click](https://stackoverflow.com/questions/44724185/element-myelement-is-not-clickable-at-point-x-y-other-element-would-receiv) – undetected Selenium Mar 13 '18 at 12:28
  • 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. – Shubham srivastava Mar 15 '18 at 16:44

9 Answers9

41

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

element = driver.find_element_by_xpath(xpath)
driver.execute_script("arguments[0].click();", element)
wrecks
  • 586
  • 1
  • 4
  • 5
16

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

Alichino
  • 1,668
  • 2
  • 16
  • 25
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]);
0

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

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);
flyingfishcattle
  • 1,817
  • 3
  • 14
  • 25
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

Julian
  • 4,396
  • 5
  • 39
  • 51
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

gorandp
  • 500
  • 5
  • 11
0

This code resolve 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);
Joc380
  • 25
  • 7
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
noraj
  • 3,964
  • 1
  • 30
  • 38