Selenium测试脚本通过新的ajax登录表单登录谷歌帐户 [英] Selenium test scripts to login into google account through new ajax login form

查看:291
本文介绍了Selenium测试脚本通过新的ajax登录表单登录谷歌帐户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以编写脚本来将我的电子邮件地址放入电子邮件元素中。但是,一旦点击下一步脚本,谷歌就会使用ajax动态地将该电子邮件元素替换为密码元素。这是我被困住的地方,无法在该元素中提供密码而且无法登录。

I am able to write scripts to give my email address into email element. But once click next through scripts Google uses ajax to replace that email element to password element dynamically. This is where I am stuck and won't be able to give password in that element and no login.

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

请编写selenium测试脚本来实现此目的。

Please write the selenium test scripts to achieve this.

推荐答案

以下是使用您的有效凭据访问网址 https://accounts.google.com/signin 登录的代码块,并打印页面控制台上的标题

Here is the code block to access the url https://accounts.google.com/signin login with your valid credentials and print the Page Title on your console:

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

控制台输出:

Google Accounts

这篇关于Selenium测试脚本通过新的ajax登录表单登录谷歌帐户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆