首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在selenium2.0中使用selenium1.0的API

在selenium2.0中使用selenium1.0的API

作者头像
流柯
发布2018-08-30 17:15:09
1.7K0
发布2018-08-30 17:15:09
举报
文章被收录于专栏:流柯技术学院流柯技术学院

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

}

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015-03-11 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档