1、安装jdk并配置环境变量:

jdk安装
jdk下载地址: http://www.oracle.com/technetwork/java/javase/downloads/index.html
环境变量配置,如:
CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar
JAVA_HOME=D:\Program Files\Java\jdk1.6.0_10
PATH=%JAVA_HOME%\bin

2、安装Firefox,Selenium IDE,Firebug和xpahter

安装FireFox

Firefox版本有一定限制,需要和selenium IDE相匹配。
下载地址: http://www.firefox.com.cn/download/

安装Selenium IDE
Selenium IDE是基于FIREFOX浏览器的一个插件,提供GUI界面来运行Selenium测试。Selenium IDE提供脚本录制和回放功能,可以将用户在浏览器中执行的操作记录下来,生成各种形式的脚本,可以将这些脚本保存供selenium使用。Selenium IDE主要是用在Selenium 1.0中,在Selenium 2.0中基本不使用。
1)下载Selenim IDE
下载地址:http://seleniumhq.org/projects/ide/

2)安装:直接把下载的Selenium IDE文件拖到FireFox浏览器窗口中,按提示操作即可安装成功。

安装Firebug
1)打开Firefox浏览器
2)点击菜单“工具(T)”,下拉列表中选择“附加组件”。
3)“获取附加组件”
4)在搜索里输入“firebug”,稍等即可。
5)点击“添加至Firefox”
6)OK,重启浏览器即可。

安装xpahter
1)打开Firefox浏览器
2)点击菜单“工具(T)”,下拉列表中选择“附加组件”。
3)“获取附加组件”
4)在搜索里输入“xpahter”,稍等即可。
5)点击“添加至Firefox”
6)OK,重启浏览器即可。

安装xpath checker

1)打开Firefox浏览器
2)点击菜单“工具(T)”,下拉列表中选择“附加组件”。
3)“获取附加组件”
4)在搜索里输入“xpath checker”,稍等即可。
5)点击“添加至Firefox”
6)OK,重启浏览器即可。

3、安装eclipse

安装eclipse

4、安装selenium webdriver

1)下载地址: http://code.google.com/p/selenium/downloads/list

官方UserGuide:http://seleniumhq.org/docs/

2)下载:selenium-server-standalone-2.44.0.jar和selenium-java-2.44.0.zip(使用java语言的下载该包)。 
3)解压下载的selenium-java-2.44.0.zip文件

5、selenium2使用:

1)在Eclipse里新建一个project,然后引用selenium-java-2.44.0.zip解压后的selenium-java-2.44.0.jar,及libs下的jar包。

2)新建一个class“Seleniumcn”把代码贴进去,如果代码没错误就可以运行了。例如下面:

package com.hxh.test;

import org.testng.annotations.AfterMethod;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeMethod;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import com.thoughtworks.selenium.webdriven.WebDriverBackedSelenium; public class SeleniumTest{
private WebDriver driver;
@BeforeMethod
@BeforeClass
public void setUp(){
System.setProperty("webdriver.ie.driver", "C:\\Program Files (x86)\\Internet Explorer\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
} @Test(invocationCount=3)
public void testLogic(){
driver.get("http://www.baidu.com/");
System.out.println("打开链接——>");
WebDriverWait wait = new WebDriverWait(driver, 100);
WebElement element = wait.until(new ExpectedCondition<WebElement>() {
@Override
public WebElement apply(WebDriver d) {
return d.findElement(By.id("kw"));
}
});
if(element!=null){
System.out.println("成功打开连接~~~~~~~~O(∩_∩)O~");
}
} @AfterMethod
public void tearDown(){
if(driver!=null){
driver.quit();
}
}
}

正常运行后,这几行代码将会打开IE浏览器,然后转跳到百度首页。

并关闭IE浏览器。

(以上内容参考群共享某word资料,不知具体作者是谁哈~)

selenium2(WebDriver)环境搭建的更多相关文章

  1. Selenium2 WebDriver环境搭建

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

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

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

  3. webDriver环境搭建与测试

    1.安装jdk 2.安装eclipse 3.安装selenium 由于使用的是开发语言是java,因此需要安装java版的selenium包.下载地址:http://pan.baidu.com/s/1 ...

  4. 转:python webdriver 环境搭建

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

  5. RobotFramework+Selenium2+Appium环境搭建

    转载:https://www.cnblogs.com/testway/p/7372326.html 装python 2.7 RobotFramework是python2 写的,图形界面使用的wxpyt ...

  6. python webdriver 环境搭建详解

    学了一个月用java编写selenium driver 测试脚本,也将公司做的系统基本可用的模块做了一次自动化,虽然写的比较简陋,但是基本可用跑一遍,并用testNG生成了测试报告. 学习方式无非是: ...

  7. 百度搜索_Selenium WebDriver 环境搭建和错误调试_chromedriver_win32必须下载否则无法测试chrome

    转自:  http://www.360doc.com/content/14/0821/18/597197_403634783.shtml zTree 东西不多,我也一直使用着原始的人工测试手段,随着内 ...

  8. Windows环境下,python webdriver环境搭建

    最近刚开始学习selenium,这是我从虫师的<selenium2自动测试实战--基于Python语言>这本书上学到搭建环境的步骤,里面有加上我的一些总结,希望对大家有所帮助!   准备工 ...

  9. selenium webdriver 环境搭建--java

    selenium java环境的安装可以分为三个部分:jdk.eclipse和selenium. jdk jdk(java development kit)是sun公司针对java开发人员的产品,是整 ...

  10. 二. Python WebDriver环境搭建

    1. 安装Selenium 在命令行中输入: 显示安装成功: 2. 测试例子 打开百度页面并在输入框输入搜索内容(默认为firework) # 1. Selenium默认为Firefox.验证 fro ...

随机推荐

  1. SQL语言基础

    主要学习链接1 http://www.cnblogs.com/anding/p/5281558.html 搜索学习链接2 http://www.cnblogs.com/libingql/p/41342 ...

  2. Gridview实现删除弹出提示信息

    实现方法: 双击GridView的OnRowDataBound事件: 在后台的GridView1_RowDataBound()方法添加代码,最后代码如下所示:       protected void ...

  3. git乱码问题解决

    etc\gitconfig文件中增加以下内容: [gui]     encoding = utf-8 [i18n]     commitencoding = gbk [svn]     pathnam ...

  4. [JSP]Maven+SSM框架(Spring+SpringMVC+MyBatis) - Hello World

    来源:http://blog.csdn.net/zhshulin/article/details/37956105?utm_source=tuicool&utm_medium=referral ...

  5. 小知识:Python函数传递变长

    先来实践一把: def f1(*args): print(args) f1(1,2,3,4) 得出:(1, 2, 3, 4) ----- 是一个元祖 Part 1: *args可以传递任意多的数,ar ...

  6. shell 脚本 exit 1 报错:numeric argument required问题解决

    原因是在window环境编辑会有特殊字符,解决办法:sed -i'' "s/\r//" file_name

  7. centos6升级python2.7

    #下载python #wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2 #安装支持https yum install opens ...

  8. 01HTTP服务&AJAX编程

    HTTP服务&AJAX编程 一.服务器         1. 什么是服务器? 能够提供某种服务的机器(计算机)称为服务器. 2.服务器的分类:              1.按系统分类:Lin ...

  9. ConCurrent in Practice小记 (2)

    Java-ConCurrent2.html :first-child{margin-top:0!important}img.plugin{box-shadow:0 1px 3px rgba(0,0,0 ...

  10. CSS实现DIV水平自适应居中

    DIV水平自适应居中 <!DOCTYPE html> <html lang="cn"> <head> <meta charset=&quo ...