元素对于使用java的Gmail密码字段Selenium WebDriver不可交互

元素对于使用java的Gmail密码字段Selenium WebDriver不可交互,java,selenium-webdriver,gmail,Java,Selenium Webdriver,Gmail,我目前正在尝试登录我的测试Gmail邮箱。登录正常,但对于密码字段,我始终会得到: ElementNotInteractiableException:元素不可交互 我使用了不同的xpath的/id的(它们非常明确),但没有什么帮助。 代码很简单: public class OpenGmail { public static void main(String[] args){ System.setProperty ("webdriver.chrome.driver", "C

我目前正在尝试登录我的测试Gmail邮箱。登录正常,但对于密码字段,我始终会得到:

ElementNotInteractiableException:元素不可交互

我使用了不同的
xpath的
/
id的
(它们非常明确),但没有什么帮助。 代码很简单:

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);
        }
    }
}
我试图分析html,但在
WebElement
中有
aria hidden=“true”

<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>

输入您的密码
我是否正确理解
WebElement
WebDriver
认为是隐藏的


例如,是否可以通过JS将数据发送到此字段?我想尝试使用setAttribute,但我以前从未使用过JS。

对于gmail登录页面中的密码输入,您可以使用以下定位器:
By.name(“密码”)
,似乎您需要等待此元素。首先,以下几点:

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
然后尝试下面的代码:

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");

欢迎来到SO。请花点时间阅读。它将帮助你设计出可靠的问题,希望能得到有用的答案。FWIW:众所周知,gmail很难通过webdriver实现自动化;考虑使用Gmail API。谢谢!我将来的问题将更加符合“如何做”的原则。我也在努力掌握API,但今天@frianH的答案对我来说更方便。非常好。这是一张赞成票:)