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)); wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(objectByLocator(strElementIdentifier))); } /// <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); waitForElementClickable(strElementIdentifier); driver.WrappedDriver.FindElement(objectByLocator(strElementIdentifier)).Click(); }
No comments:
Post a Comment