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);
Post a Comment