WebDriver中启动不同的浏览器

摘要:
进口penqa.selenium.chrome。铬河水;importorg.openqa.selenium.firefox。FirefoxDriver;importorg.openqa.selenium.ie.InternetExplorerDriver;publicclassFirstExample{/***@paramargs*@throwsInterrup
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;


public class FirstExample {

    /**
     * @param args
     * @throws InterruptedException 
     */
    public static void main(String[] args) throws InterruptedException {

        //打开指定地方的firefox
//        System.setProperty("webdriver.firefox.bin","C:\Users\test\AppData\Local\Mozilla Firefox\firefox.exe");
//        FirefoxDriver driver = new FirefoxDriver();
        
        //打开IE8
//        System.setProperty("webdriver.ie.driver","E:\driver\IEDriverServer.exe");
//        InternetExplorerDriver driver = new InternetExplorerDriver();
        
        //打开chrome浏览器
        System.setProperty("webdriver.chrome.driver","E:\driver\chromedriver.exe");
        ChromeDriver driver = new ChromeDriver();
        
        driver.get("http://localhost:8080/test/login.jsp");
        driver.findElementByName("userName").sendKeys("test");
        driver.findElementById("userPwd").sendKeys("test");
        driver.findElementById("login").click();

        System.out.println(driver.findElementByXPath("//*[@id='modify_psw']/a").getText());
        
        driver.close();
    }

}

 备注:
    1. firefox浏览器

           selenium版本:2.44.0   firefox的版本:33.1

    2. chrome浏览器

           selenium版本:2.44.0   chrome版本: 33.0.1750.154   相应的chromedriver的驱动(驱动与selenium和chrome的版本也是对应的)

   3. IE浏览器

           selenium版本:2.44.0   IE版本: IE8   相应的IE的驱动(驱动与selenium和IE的版本也是对应的)

免责声明:文章转载自《WebDriver中启动不同的浏览器》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇欢快的使用谷歌搜索16进制与字符串、字节数组之间的转换下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Ubuntu 14.04 LTS下安装Google Chrome浏览器

在Ubuntu14.04下安装Google Chrome浏览器非常简单,只要到Chrome的网站下载Deb安装包并进行安装即可。当然你也可以使用APT软件包管理器来安装Google Chrome浏览器,如果你想使用APT软件包管理器安装Google Chrome浏览器的话,本文将介绍这两种方法。 目前Linux下的Google Chrome浏览器有三个版本...

使用Selenium和openCV对HTML5 canvas游戏进行自动化功能测试(一)

上一篇讲了HTML5 canvas游戏的基本工作原理,接下来讲如何进行自动化功能测试。 Selenium是一个跨平台的跨浏览器的对网页进行自动化测试的工具。从Selenium 2.0开始Selenium就和WebDriver合体了。如果你还不了解Selenium怎么用,可以看看官网上的例子。Selenium支持各种语言的binding,方便起见,下面的测试...

Appium(八):Appium API(二) 元素等待、元素操作

1. 元素等待 我们在使用脚本的时候,可能会由于网络、服务器处理、电脑等原因,我们想要找的元素没有加载出来,这个时候如果直接定位就可能会报错。 这个时候我们就可以设置元素等待了。 什么叫元素等待呢? 就是WebDriver定位页面元素时如果没有找到,就会在指定时间内一直等待的过程。 元素等待一共分为两种类型:显示等待和隐式等待。 1.1 隐式等待 隐式等待...

用chrome模拟微信浏览器访问页面

有的网页通过限制user agent 来达到禁止在微信浏览器以外的地方访问,我们通过chrome修改user agent即可破解。 CHROME浏览器,进入开发者模式 切换到手机浏览模板 打开 Network,有下拉菜单中选择Custom->Add 选择Devices,再点击Add custom device 然后在user agent中填写下面的...

selenium从入门到应用

本系列所有代码 https://github.com/zhangting85/simpleWebtest 本文将介绍一个Java+TestNG+Maven+Selenium的web自动化测试脚本环境下selenium页面对象脚本的编写,并提供全部代码。 文中将看到,使用selenium编写的一个高复用性、高可维护性的测试框架的核心部分。 背景就不多介绍了,...

安装chrome扩展json-handle

chrome插件安装 方式一,在线安装 直接插到json-handle地址,添加即可 https://chrome.google.com/webstore/detail/json-handle/iahnhfdhidomcpggpaimmmahffihkfnj?hl=zh-CN 国内部分用户无法访问到Google的服务,所以还可以使用方式二,离线安装。 方式...