无法找到密码输入对象使用selenium登录谷歌

时间:2017-08-02 03:20:26

标签: selenium phantomjs

我在selenium中使用PhantomJS作为驱动程序。在这里,我发现插入电子邮件地址没有问题。但是,在单击下一个之后,应该有一个名为“password”的输入标记。但是,在等待之后,我无法获得所需的“密码”标签。它显示错误没有找到元素。有时,我收到以下错误(显示堆栈跟踪):

org.openqa.selenium.InvalidElementStateException: {"errorMessage":"Element is not currently interactable and may not be manipulated","request":{"headers":{"Accept-Encoding":"

因为,我等了足够的时间,以下代码必须正常工作。 以下是工作的代码段。

    driver.get("https://accounts.google.com/ServiceLoginAuth");   
    driver.findElement(By.id("identifierId")).sendKeys("xxxxxxxx");
    driver.findElement(By.id("identifierNext")).click();

    WebDriverWait wait = new WebDriverWait(driver, 20);
    wait.until(ExpectedConditions.presenceOfElementLocated(By.name("password"))); 
    driver.findElement(By.name("password")).sendKeys("xxxxxxxx");
    driver.findElement(By.id("passwordNext")).click();

以下是显示电子邮件google sign in page的输入字段的具体html:

input type="email" class="whsOnd zHQkBf" jsname="YPqjbf" autocomplete="username" spellcheck="false" tabindex="0" aria-label="Email or phone" name="identifier" id="identifierId" dir="ltr" data-initial-dir="ltr" data-initial-value=""

下一步按钮的ID为“ identifierNext ”,隐藏密码字段为:

input type="password" name="hiddenPassword" jsname="RHeR4d" class="yb9KU" tabindex="-1" 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" autocorrect="off" dir="ltr" data-initial-dir="ltr" data-initial-value=""

现在,问题是,我使用等待机制重新加载页面,以便我可以获得密码插入页面。但是,使用Selenium我找不到'密码'的命名标签。 我认为点击工作不正常。是否有可能无法点击下一步

2 个答案:

答案 0 :(得分:0)

试试这个:

driver.findElement(By.xpath("//input[1]"));

或者这个:

WebDriverWait wait = new WebDriverWait(driver, 100);
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@type='password']")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@type='password']")));
WebElement elementpwd = driver.findElement(By.xpath("//input[@type='password']"));

我希望它有所帮助。

答案 1 :(得分:0)

请使用Chrome浏览器

找到使用selenium网络驱动程序发送电子邮件的完整代码

public class Newtest {

RETURN;

}