Solved ElementClickInterceptedException

 Table of content


ElementClickInterceptedException: Element not clickable

ElementClickInterceptedException might have occurred when you are trying to click an element, the element could be a button, radio button or checkbox, or just a click operation.

ElementClickInterceptedException occurs when the target element that you want to click is overlaid by some other element in the web page.

Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException:
element click intercepted:
Element <input value="Google Search" aria-label="Google Search" name="btnK" type="submit">
 is not clickable at point (596, 368).
Other element would receive the click: <span>...</span>

For example, when you have an element below the dropdown/ Submenu; then you might have faced this kind of error. Sometimes some model pop-ups also can cause this kind of overlay on the element, so when you try to click such kind of element then you will receive an element not clickable exception.

In the below example, we are going to click on the Google search button after entering the term Facebook on the search bar. In the below image you can see, the auto suggestions are overlaid on the Google search button.

element-not-clickable-seleniumReasons for Element Click Intercepted Exception problem

  • Selenium/Automation tools work much faster than the response of the application
  • Sometimes, the speed of the internet and system hardware makes the application to run slower
  • The developer might have added a parent element for the target element
  • Poor design of the website
Ways that do not solve the problem:
  • Clicking the element again
  • Waiting using sleep
  • Waiting till element becomes clickable
Solution:

We have to trigger the click operation using the JavaScript executor.

public static void main(String[] args) throws Exception {
	System.setProperty("webdriver.chrome.driver", "D:\\PATH\\chromedriver.exe");
	WebDriver driver = new ChromeDriver();
	driver.manage().window().maximize();
	driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
	driver.get("https://google.com");

	driver.findElement(By.name("q")).sendKeys("facebook");
	WebElement searchButton = driver.findElement(By.xpath("(//input[@value='Google Search'])[2]"));
	JavascriptExecutor js = (JavascriptExecutor)driver;
	js.executeScript("arguments[0].click()", searchButton);
}
JQuery to handle ElementClickInterceptedException

Instead of using the selenium find methods, you can also use JQuery methods to find the element and then click it.

$x means find element using xpath

driver.get("https://google.com");

driver.findElement(By.name("q")).sendKeys("facebook");
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("$x(\"(//input[@value='Google Search'])[2]\").click()");