1、安装jdk

2、安装eclipse

3、安装selenium

由于使用的是开发语言是java,因此需要安装java版的selenium包。下载地址:http://pan.baidu.com/s/1hq6mebE,下载的版本为:selenium-java-2.53.0。下载完成后,进行解压,得到如下目录:

下载完jar包后,在已经创建的项目上右键,选择properties,选择java Build Path,选择导入额外的jar包,详情如下:

导入jar包后:

4、安装浏览器驱动

Firefox--selenium原生支持,不需要安装浏览器驱动

IE--需要安装浏览器驱动

chrome--需要安装浏览器驱动

以IE为例:

首先下载IEDriverServer.exe,将该驱动防止到IE浏览器安装路径下:C:\Program Files (x86)\Internet Explorer

配置系统路径path,配置如下:

5、接下来编写一个简单的程序,测试环境搭建是否通过

import org.openqa.selenium.*;
import org.openqa.selenium.firefox.*;
import org.openqa.selenium.chrome.*;
import org.openqa.selenium.ie.*;
public class WebDriverLearn {

WebDriver driver = new InternetExplorerDriver();       
        driver.get("https://www.baidu.com/");        
    }
}

运行:

报错如下:

Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.ie.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver. The latest version can be downloaded from http://selenium-release.storage.googleapis.com/index.html
    at com.google.common.base.Preconditions.checkState(Preconditions.java:199)
    at org.openqa.selenium.remote.service.DriverService.findExecutable(DriverService.java:109)
    at org.openqa.selenium.ie.InternetExplorerDriverService.access$0(InternetExplorerDriverService.java:1)
    at org.openqa.selenium.ie.InternetExplorerDriverService$Builder.findDefaultExecutable(InternetExplorerDriverService.java:167)
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:296)
    at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:251)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:172)
    at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:146)
    at WebDriverLearn.main(WebDriverLearn.java:27)

报错原因:

找不到IE浏览器相关文件,需要设置下system property。利用System.setProperty方法来添加路径,代码更新如下:

import org.openqa.selenium.*;
import org.openqa.selenium.ie.*;
public class WebDriverLearn {
    public static void main(String[] args) {
        System.setProperty("webdriver.ie.driver", "C:/Program Files (x86)/Internet Explorer/IEDriverServer.exe"); //指定IE浏览器安装路径
        WebDriver driver = new InternetExplorerDriver();   
        driver.get("https://www.baidu.com/");        
    }
}

运行本段代码,能够顺利打开IE浏览器。

注意:本文使用的selenium-java-2.53.0.jar,IE浏览器为IE9.

selenium和不同的浏览器,会有不同的兼容性问题,需要选择正确的相互兼容的selenium和浏览器。目前只找到selenium-java-2.53.0.jar和IE9兼容.

webDriver环境搭建与测试的更多相关文章

  1. Python+Selenium+webdriver环境搭建(windows)以及相关资源下载链接

    今天记录一下测试小菜鸟alter在测试入门的一点关于python+Selenium+webdriver环境搭建的经历以及资源分享.欢迎交流学习,批评指正. 一.Python的下载与安装 1.pytho ...

  2. Tensorflow object detection API ——环境搭建与测试

    1.开发环境搭建 ①.安装Anaconda 建议选择 Anaconda3-5.0.1 版本,已经集成大多数库,并将其作为默认python版本(3.6.3),配置好环境变量(Anaconda安装则已经配 ...

  3. 【运维技术】kafka三实例集群环境搭建及测试使用

    kafka三实例集群环境搭建及测试使用 单机搭建分为两部分:1. 软件安装启动 2. 软件配置 软件安装启动: # 切换到目录 cd /app # 获取kafka最新安装包,这边使用的是镜像地址,可以 ...

  4. Tensorflow object detection API(1)---环境搭建与测试

    参考: https://blog.csdn.net/dy_guox/article/details/79081499 https://blog.csdn.net/u010103202/article/ ...

  5. C++调用Lua编程环境搭建及测试代码示例

    C++调用Lua编程环境搭建及测试代码示例 摘要:测试环境是VS2005+LuaForWindows_v5.1.4-45.exe+WIN7 1.安装lua开发环境LuaForWindows_v5.1. ...

  6. 【转载】基于RedHatEnterpriseLinux V7(RHEL7)下SPEC CPU 2006环境搭建以及测试流程(之一)——介绍、安装准备、安装、config文件以及运行脚本介绍

    基于RedHatEnterpriseLinux V7(RHEL7)下SPEC CPU 2006环境搭建以及测试流程(之一)--介绍.安装准备.安装.config文件以及运行脚本介绍 其他 2018-0 ...

  7. Mybatis环境搭建及测试

    1.新建java project,导入相应jar包 本次使用到的mybatis-3.2.7版本 mybatis需要jar包:mybatis-3.2.7.jar.lib文件下的依赖jar mysql驱动 ...

  8. 转:python webdriver 环境搭建

    第一节 环境搭建准备工具如下:-------------------------------------------------------------下载 python[python 开发环境]ht ...

  9. Selenium2 WebDriver环境搭建

    1.下载Selenium Client Servers包 在Selenium官网上可以下载到最新的开源的包http://seleniumhq.org/download/,根据编写测试脚本所使用的语言下 ...

随机推荐

  1. php设计模式之单例模式使用示例

    单例模式也就是只能实例化一次,也就代表在实例化时不可能使用new关键字,下面是使用示例,大家参考使用吧   <?php class EasyFramework_Easy_Mysql{     p ...

  2. openfire 连接sqlserver 2008 的一个问题

    由于本人的笨拙,搞了一天才终于搞好,说实在的问题归根结底还是在sql上,要相信openfire是没问题的.好了,不瞎扯了,说正题. 本人的机器环境为:win7.sqlserver 2008.jdk1. ...

  3. Xcode LaunchImage 载入界面大小设置

    iPhone Portrait iOS 8-Retina HD 5.5 (1242×2208) @3xiPhone Portrait iOS 8-Retina HD 4.7 (750×1334) @2 ...

  4. python中的告警处理

    在Python中,遇到异常时,一类是直接抛出异常,exception:另一类直接告警warning. 对于后者,通常是打印一句话.前者则或中断程序执行. 考虑到避免由于告警导致后续的不可预知的错误,可 ...

  5. 创建并追加img元素(jquery!)

    有几种方法 但都需要你指定一个节点 根据这个节点进行添加 如现有一节点Id为pr:一,向该节点内部后方添加:1 $("#pr").append("<img src= ...

  6. Java监控工具介绍,VisualVm ,JProfiler,Perfino,Yourkit,Perf4J,JProbe,Java微基准测试

    本文是本人前一段时间做一个简单Java监控工具调研总结,主要包括VisualVm ,JProfiler,Perfino,Yourkit,Perf4J,JProbe,以及对Java微基准测试的简单介绍, ...

  7. z-fighting在unity中的解决方式

    如果在画面中,发现有画面闪烁的问题.那么大多数情况下是z-fighting引起的, 解决方案: 1, 在每个场景中,找到那个MainCamera,然后在Inspector上,找到MainCamera的 ...

  8. hdu 5876 (补图BFS) Sparse Graph

    题目:这里 题意: 相当于一开始给一个初始好了的无向完全图给你,然后给让你删除m条边,再给你一个点v,最后问你在剩下的图里从这个点v出发能到达所有边点的最小路径是多少? 一看是所有点的最小路径,一看就 ...

  9. error: src refspec master does not match any. 错误处理办法

    自从上次学了git之后,很少用.今天在使用 本地仓库使用如下命令初始化: $ git init 之后使用如下命令添加远程库: $ git remote add origin git@github.co ...

  10. MFC学习笔记

    获取窗口句柄 FindWindow               根据窗口名获取 GetSafehWnd                取你程序所在窗口类的句柄 GetActiveWindow     ...