打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
WebDriver拾级而上·之十一 在selenium2.0中使用selenium1.0的AP
Selenium2.0中使用WeDriver API对页面进行操作,它最大的优点是不需要安装一个selenium server就可以运行,但是对页面进行操作不如selenium1.0的Selenium RC API那么方便。
Selenium2.0提供了使用Selenium RC API的方法:
// 我用火狐浏览器作为例子
WebDriver driver = new FirefoxDriver();
String baseUrl ="http://www.google.com";
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl);
// 执行selenium命令
selenium.open("http://www.google.com");
selenium.type("name=q", "cheese");
selenium.click("name=btnG");
WebDriver driverInstance = ((WebDriverBackedSelenium)selenium).getUnderlyingWebDriver();
selenium.stop();
分别使用WebDriver API和SeleniumRC API写了一个Login的脚本,很明显,后者的操作更加简单明了。
(1)WebDriver API写的Login脚本:
public void login() {
driver.switchTo().defaultContent();
driver.switchTo().frame("mainFrame");
WebElement eUsername= waitFindElement(By.id("username"));
eUsername.sendKeys(manager@ericsson.com);
WebElement ePassword= waitFindElement(By.id("password"));
ePassword.sendKeys(manager);
WebElementeLoginButton = waitFindElement(By.id("loginButton"));
eLoginButton.click();
}
(2)SeleniumRC API写的Login脚本:
public void login() {
selenium.selectFrame("relative=top");
selenium.selectFrame("mainFrame");
selenium.type("username","manager@ericsson.com");
selenium.type("password","manager");
selenium.click("loginButton");
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
软件测试工程师‖怎么编写测试脚本
python实现自动化脚本编写
课件5——自动化测试模型
Selenium PO模式实现
Selenium抓取HTTPS请求
入手爬虫利器:phantomjs+selenium、自动填充文本框、自动点按钮
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服