zoukankan      html  css  js  c++  java
  • 在selenium2.0中使用selenium1.0的API

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

    }

  • 相关阅读:
    关于 TIdHttp
    DCEF3 相关资料
    WPF RichTextBox 控件常用方法和属性
    Delphi Data Type to C# Data Type
    获取 CPU 序列号
    Visual Studio 调用 Delphi DLL 会退出的解决方案
    IDHttp的基本用法(转)
    TChromeTabs 优化改进
    java与json转换
    js charAt()方法
  • 原文地址:https://www.cnblogs.com/liu-ke/p/4330203.html
Copyright © 2011-2022 走看看