Selenium Exception Error - Element is not clickable at point (x,y). Other element would receive the click

SeleniumAutomation TestingTesting Tools

We may encounter the Selenium Exception Error - Element is not clickable at point(x,y). Other element would receive the click while working Selenium webdriver.

This is normally seen while executing Selenium tests from the Chrome browser and not with other browsers like IE and Firefox. This happens because the Chrome browser could not compute the correct location of a webelement.

Besides, in the Chrome browser, an element is clicked in its middle position. This exception can also be encountered owing to synchronization issues happening between the application and Selenium.

There exists some solutions to fix this issue as listed below −

  • We should ensure that we are using the latest version of the chromedriver and it is compatible with the Chrome browser version we have in our local system.

  • Obtain the coordinates of a webelement and then perform click on it using methods in Actions class.

Syntax

WebElement elm = driver.findElement(By.tagName("input"));
//instance of Point class
Point location = elm.getLocation();
//get x, y coordinates
int m = location.getX();
int n = location.getY();
//instance of Actions class
Actions a = new Actions(driver);
a.moveToElement(elm,m,n).click().build().perform();
  • Obtain the coordinates of a webelement and click it using JavaScript Executor.

Syntax to get x-coordinate −

WebElement l = driver.findElement(By.tagName("input"));
JavascriptExecutor j =(JavascriptExecutor)driver;
j.executeScript(
   "window.scrollTo(0,"l.getLocation().x+")");
l.click();

Syntax to get y-coordinate −

WebElement l = driver.findElement(By.tagName("input"));
JavascriptExecutor j =(JavascriptExecutor)driver;
"window.scrollTo(0,"l.getLocation().y+")");
l.click();
raja
Published on 29-Jun-2021 08:38:35
Advertisements