找不到密码输入对象登录谷歌与硒



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

org.openqa.selenium.InvalidElementStateException: {"errorMessage":"Element 当前不可交互,可能无法操作","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();

以下是显示电子邮件谷歌登录页面输入字段的特定 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是'标识符Next',hhe隐藏的密码字段:

输入类型="密码" 名称="隐藏密码" 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="输入您的密码" name="password" autocapitalize="off" autocorrect="off" dir="ltr" data-initial-dir="ltr" data-initial-value=">

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

试试这个:

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

我希望它有所帮助。

请找到使用Selenium网络驱动程序使用Chrome浏览器为Gmail发送电子邮件的完整代码

public class Newtest {
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub

System.setProperty("webdriver.chrome.driver", "C:\Users\Tharun\Desktop\work\chromedriver.exe");
WebDriver driver= new ChromeDriver();
driver.get("https://www.google.com");
driver.findElement(By.xpath("//*[@id='gb_70']")).click();
driver.findElement(By.xpath("//*[@id='identifierId']")).sendKeys("*******@gmail.com");
driver.findElement(By.xpath("//*[@id='identifierNext']/content/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//input[@type='password']")).sendKeys("*******");
driver.findElement(By.xpath("//*[@id='passwordNext']/content/span")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id="gbw"]/div/div/div[1]/div[2]/a")).click();
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id=':ir']/div/div")).click();
Thread.sleep(5000);
driver.findElement(By.cssSelector("#\3a og")).sendKeys("*******@gmail.com");
driver.findElement(By.cssSelector("#\3a ny")).sendKeys("This is my selenium web driver automation code ");
Thread.sleep(5000);
driver.findElement(By.xpath("//*[@id=':p3']")).sendKeys("This is my selenium web driver automation code ");
Thread.sleep(2000);
driver.findElement(By.xpath("//*[@id=':no']")).click();
}
} 

最新更新