I'm currently trying to log in to my test Gmail box. The login is ok but for the password field I always get an:
ElementNotInteractableException: element not interactable.
I used different xpath's
/ id's
(they are quite explicit) but it was not helpful.
The code is simple:
public class OpenGmail {
public static void main(String[] args){
System.setProperty ("webdriver.chrome.driver", "C:\\Chromedriver\\chromedriver_win32\\chromedriver.exe");
WebDriver wd = new ChromeDriver();
try {
wd.get("https://mail.google.com/mail/u/0/h/1pq68r75kzvdr/?v%3Dlui");
wd.findElement(By.xpath("//input[@type='email']")).sendKeys("[email protected]");
wd.findElement(By.id("identifierNext")).click();
//Variant1
wd.findElement(By.xpath("//input[@type='password']")).sendKeys("qwerty123");
//Variant2
wd.findElement(By.id("password")).sendKeys("qwerty123");
System.out.println("clicked");
wd.findElement(By.xpath("//input[@class='whsOnd zHQkBf']")).sendKeys("qwerty123");
}catch (Exception e){
System.out.println(e);
}
}
}
I tried to analyze the html and there is aria-hidden="true"
in the WebElement
:
<input type="password" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="current-password" spellcheck="false" tabindex="0" aria-label="Enter your password" name="password" autocapitalize="off" dir="ltr" data-initial-dir="ltr" data-initial-value="">
<div jsname="YRMmle" class="AxOyFc snByac" aria-hidden="true">Enter your password</div>
Do I understand right that the WebElement
is considered hidden by WebDriver
?
Is it possible to send data to this field by JS, for example? I wanted to try setAttribute JavaScriptexecutor setAttribute value on selenium but I've never used JS before.
For password input you mean in gmail sign in pages, you can use this locator: By.name("password")
and it seem like you need wait this element. First, following import:
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
And try the bellow code:
wd.get("https://mail.google.com/mail/u/0/h/1pq68r75kzvdr/?v%3Dlui");
//wait email input
WebElement email = new WebDriverWait(wd, 10).until(ExpectedConditions.elementToBeClickable(By.name("identifier")));
email.sendKeys("[email protected]");
wd.findElement(By.id("identifierNext")).click();
//wait password input
WebElement password = new WebDriverWait(wd, 10).until(ExpectedConditions.elementToBeClickable(By.name("password")));
password.sendKeys("qwerty123");
System.out.println("clicked");