March 15, 2021

How to handle OpenQA.Selenium.ElementClickInterceptedException: element click intercepted

  March 15, 2021

 This exception will be thrown by selenium mostly while loading a page. If our application is an angular application chance of this exception is more.

Most probably a spinner or any other loading page will be blocking our code from clicking the desired object.

One such scenario is shown below, where a spinner blocks our element to click.

OpenQA.Selenium.ElementClickInterceptedException: element click intercepted: Element <a class="secondary-color" style="border-width: 2px; border-style: solid; border-color: red;">...</a> is not clickable at point (1239, 86). Other element would receive the click: <div class="spinnerTemplate">...</div>

Here instead of our object, the script will try to click on the spinner and fails.

This issue can be solved by providing adequate wait or by adding element-ready conditions before clicking on the desired element.

A sample code is given below.

/// <summary>
/// Wait for element visibility for the specified time
/// </summary>
/// <param name="elementIdentifier"></param>
/// <param name="intTimeSec"></param>
public void waitForElementClickable(string strElementIdentifier, int intTimeSec = 30)
	writeLog("info", "Waited for the element and found : " + strElementIdentifier);
	WebDriverWait wait = new WebDriverWait(driver.WrappedDriver, TimeSpan.FromSeconds(intTimeSec));


/// <summary>
/// Method to click on an element
/// </summary>
/// <param name="elementIdentifier"></param>
/// <param name="ElementName"></param>
public void clickElement(string strElementIdentifier, String strElementName = "")
	writeLog("info", "Clicking on element : " + strElementName);


Thanks for reading How to handle OpenQA.Selenium.ElementClickInterceptedException: element click intercepted

« Prev Post

No comments:

Post a Comment

Fixing javascript error: Cannot read properties of null (reading 'querySelector') issue when using CSS identifier in selenium

 JavaScript is another way to interact with web elements when normal selenium methods fail to act. But one issue with javascript is, it does...