How to use ElementNotInteractableException class of org.openqa.selenium package

Best Selenium code snippet using org.openqa.selenium.ElementNotInteractableException

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

ElementNotInteractableException org.openqa.selenium.ElementNotInteractableException;

ElementNotInteractableException raised due to dom element is present though the action performed on it which is not supported by the element at that moment.

Like, you have a disable submit button state which need some value in the form to get activated, when someone tries to click on the submit button then it raise ElementNotInteractableException due to disable state.

Example

The below code try to click and element which is not clickable then selenium throws ElementNotInteractableException

copy
1public void googleSearch() { 2 3 WebDriverManager.chromedriver().setup(); 4 WebDriver driver = new ChromeDriver(); 5 driver.get("https://www.google.com"); 6 driver.findElement(By.name("q")).sendKeys("facebook"); 7 8 // locate and click on first suggestion button 9 WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5)); 10 WebElement elm = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("(//div[@role = 'option']//span)[1]"))); 11 elm.click(); 12 Assert.assertTrue(ExpectedConditions.titleContains("facebook").apply(driver).booleanValue()); 13}

Solutions

  • Verify element state before performing action
  • Add waits to render the state of element
  • Verify and observe locator and state of DOM element

Code Snippets

Here are code snippets that can help you understand more how developers are using

Source:DriverBB.java Github

copy
Full Screen

Source:BasePage.java Github

copy
Full Screen

Source:SeleniumBaseFunctions.java Github

copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen
copy
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Most used methods in ElementNotInteractableException

    No methods found for this class 😞

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free