Test Scenario: Trying to capture and test Gmail Login.
Current Output: Mozilla instance opens up. Username is entered but the Password is not being entered by the WebDriver code.
System.setProperty("webdriver.gecko.driver", "C:\\Users\\Ruchi\\workspace2\\SeleniumTest\\jar\\geckodriver-v0.17.0-win64\\geckodriver.exe");
FirefoxDriver varDriver=new FirefoxDriver();
varDriver.get("http://gmail.com");
WebElement webElem= varDriver.findElement(By.id("identifierId"));
webElem.sendKeys("error59878@gmail.com");
WebElement nextButton=varDriver.findElement(By.id("identifierNext"));
nextButton.click();
varDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement wePass=varDriver.findElement(By.cssSelector(".rFrNMe.P7gl3b.sdJrJc.Tyc9J"));
wePass.sendKeys("test1");
ElementNotInteractableException
As per the documentation, ElementNotInteractableException is the W3C exception which is thrown to indicate that although an element is present on the DOM Tree, it is not in a state that can be interacted with.
Reasons & Solutions :
The reason for ElementNotInteractableException to occur can be numerous.
Temporary Overlay of other WebElement over the WebElement of our interest:
In this case, the direct solution would have been to induce ExplicitWait i.e. WebDriverWait in combination with
ExpectedCondition
asinvisibilityOfElementLocated
as follows:A better solution will be to get a bit more granular and instead of using
ExpectedCondition
asinvisibilityOfElementLocated
we can useExpectedCondition
aselementToBeClickable
as follows:Permanent Overlay of other WebElement over the WebElement of our interest :
If the overlay is a permanent one in this case we have to cast the WebDriver instance as JavascriptExecutor and perform the click operation as follows:
Now addressing the error ElementNotInteractableException in this particular context we need to add ExplicitWait i.e. WebDriverWait as follows :
You need to induce a bit of wait for the Password field to be properly rendered in the HTML DOM. You can consider configuring an ExplicitWait for it. Here is the working code to login into Gmail using Mozilla Firefox: