2

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("test@gmail.com");
            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.

frianH
  • 7,295
  • 6
  • 20
  • 45
  • Welcome to SO. Please take the time to read [ask]. It will help you craft solid questions that will hopefully get useful answers. FWIW: gmail is notoriously difficult to automate via webdriver; consider using the gmail API. YMMV. – orde Oct 03 '19 at 00:12
  • Thanks! I will form my future questions more in line to the How to. I am trying to master the API also but for today the answer from @frianH is more handy for my purpose. – Meer Distel Oct 03 '19 at 08:50
  • 1
    Very good. Here's an upvote :) – orde Oct 03 '19 at 15:38

1 Answers1

2

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("test@gmail.com");
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");
frianH
  • 7,295
  • 6
  • 20
  • 45