How To Resolve Element Click Intercepted Exception in Selenium?

Dapheny Murphy Dapheny Murphy | November 28, 2022

How To Resolve Element Click Intercepted Exception in Selenium?

Element click intercepted exception is a common exception. An independent utility must be created to handle such exceptions in any professional automation framework. There are multiple ways to handle this exception:

  1. Method-1: JavascriptExecutor click can be used in cases like when there is a dropdown suggestion list and an element that needs to be clicked gets hidden behind. This solution will do a force click on the required element and the sample code for performing this action is:

    JavascriptExecutor js = (JavascriptExecutor)driver;
    js.executeScript("arguments[0].click();", element);

  2. Method-2: Selenium wait until the element becomes clickable

    Sample Code: WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
    wait.until(ExpectedConditions.elementToBeClickable(element))); element.click();

  3. Method-3: Element not visible due to requirement of scroll down

    Sample Code: WebElement element = driver.findElement(element locator);
    ((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element); element.click();

  4. Method-4: Use action class

    Sample Code: WebElement element = driver.findElement(element Locator);
    Actions actions = new Actions(driver); actions.moveToElement(element).click().build().perform();

  5. Method-5: Use static class

    Sample Code : Thread.sleep(10000);

New call-to-action

Disclaimer

This publication is for informational purposes only and nothing contained in it should be considered legal advice. We expressly disclaim any warranty or responsibility for damages arising out of this information and encourage you to consult with legal counsel regarding your specific needs. We do not undertake any duty to update previously posted materials.

Post a Comment

We use cookies to optimize user experience. Click on "Agree and Proceed" to confirm, OR, by continuing, you implicitly accept cookies.