我在selenium中使用 PhantomJS
作为驱动程序 . 在这里,我发现插入电子邮件地址没有问题 . 但是,单击下一个后,应该有一个名为'password'的输入标记 . 但是,在等待之后,我无法获得所需的'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=""
Next 按钮的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我找不到'password'的命名标签 . 我想 click is not working properly . 是否有机会不对 Next 点击?
2 回答
试试这个:
或这个:
我希望它有所帮助 .
请使用chrome浏览器找到使用selenium web驱动程序发送电子邮件的完整代码
公共课Newtest {
}