How To Resolve Element Click Intercepted Exception in Selenium?

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:

  • 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);

  • 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();

  • 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();

  • Method-4: Use action class

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

  • Method-5: Use static class

    Sample Code : Thread.sleep(10000);

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

Categories