栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

这是

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

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

更新(2020年1月5日)

优化上面的代码块并添加几个可以使用的参数:

public class browserAppDemo {    public static void main(String[] args) throws Exception     {        System.setProperty("webdriver.chrome.driver", "C:\Utility\BrowserDrivers\chromedriver.exe");        ChromeOptions options = new ChromeOptions();        options.addArguments("start-maximized");        options.setExperimentalOption("useAutomationExtension", false);        options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));        WebDriver driver =  new ChromeDriver(options);         driver.get("https://accounts.google.com/signin")        new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='identifierId']"))).sendKeys("emailID");        driver.findElement(By.id("identifierNext")).click();        new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='password']"))).sendKeys("password");        driver.findElement(By.id("passwordNext")).click();    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401406.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号