硒测试脚本通过新的Ajax登录表单登录到Google帐户

pra*_*231 1 java selenium selenium-webdriver

我能够编写脚本以将我的电子邮件地址添加到email元素中。但是一旦通过脚本单击“下一步”,Google就会使用ajax将该电子邮件元素动态替换为password元素。这是我遇到的问题,无法在该元素中提供密码并且无法登录。

网址:https//accounts.google.com/signin/v2/identifier?flowName = GlifWebSignIn&flowEntry = ServiceLogin

请编写硒测试脚本以实现此目的。

Deb*_*anB 5

这是https://accounts.google.com/signin使用您的有效凭据访问url 登录并Page Title在控制台上打印的代码块:

String url = "https://accounts.google.com/signin";
driver.get(url);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); 
WebElement email_phone = driver.findElement(By.xpath("//input[@id='identifierId']"));
email_phone.sendKeys("your_email");
driver.findElement(By.id("identifierNext")).click();
WebElement password = driver.findElement(By.xpath("//input[@name='password']"));
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(password));
password.sendKeys("your_password");
driver.findElement(By.id("passwordNext")).click(); 
System.out.println(driver.getTitle());
driver.quit();
Run Code Online (Sandbox Code Playgroud)

控制台输出:

Google Accounts
Run Code Online (Sandbox Code Playgroud)

  • 这事有进一步更新吗?输入密码并单击“下一步”后,它说我的网络浏览器不安全。 (4认同)