ITPub博客

首页 > 应用开发 > Java > 关键字WebElement 驱动测试

关键字WebElement 驱动测试

原创 Java 作者:孤独先生 时间:2020-09-20 22:23:57 0 删除 编辑

//声明一个火狐浏览器driver对象

WebDriver driver = new FirefoxDriver();

//打开360搜索

driver.get("http://www.haosou.com/");

//找到搜索框元素

WebElement searchInput = driver.findElement(By.name("q"));

//向搜索框输入“selenium”

searchInput.sendKeys("selenium");

//找到搜索按钮

WebElement searchButton = driver.findElement(By.id("search-button"));

//点击搜索按钮

searchButton.click();

try {

//这里我们暂时用sleep方式等待页面条状,后续会讲到如何智能等待

Thread.sleep(2000);

} catch (InterruptedException e) {

e.printStackTrace();

}

//跳转之后的页面关键字输入框元素

WebElement keywordInput = driver.findElement(By.id("keyword"));

//验证输入框的内容是不是selenium

Assert.assertEquals(keywordInput.getAttribute("value"), "selenium");

//关闭浏览器

driver.quit();


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69936314/viewspace-2722679/ ,如需转载,请注明出处,否则将追究法律责任。

下一篇: 没有了~
请登录后发表评论 登录
全部评论

注册时间:2019-06-27

  • 博文量
    6
  • 访问量
    3820