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资料,不知具体作者是谁哈~)

最新文章

  1. 小项目:mini资源管理器【使用IO流:包含(Directory与DirectoryInfo、File与FileInfo的用法)】
  2. SAP研究贴之--发票校验提示移动平均价为负
  3. miracast 协议wifi display
  4. ABA problem
  5. mvn打包
  6. C++ 实现设计模式之观察者模式
  7. HDU 5306 Gorgeous Sequence
  8. java泛型简单学习
  9. [51nod1671]货物运输
  10. hdu_1028_母函数
  11. Java序列化机制和原理及自己的理解
  12. 996.ICU与死亡因素
  13. PXE:kickstart配置文件:全自动安装centos、redhat 系统的配置
  14. C#使用xpath简单爬取网站的内容
  15. .net 调用python 实例
  16. python链接Hive
  17. [20171110]_allow_read_only_corruption参数.txt
  18. es的分词器analyzer
  19. (二)apache atlas配置和运行
  20. [HTML] 动态修改input placeholder的颜色

热门文章

  1. 如何获取TypedArray?
  2. 木马轮播图代码Jq
  3. C语言中extern的用法
  4. java 工具类
  5. java学习第12天
  6. Rendering pipeline overview(读书笔记1 --- Real-Time rendering)
  7. J2EE应用监控后台执行SQL
  8. [QDB] 幽灵分享:QDataSet+TQMSSQLConverter 实战技巧
  9. Ubuntu 12.04搭建l2tp服务器记录。
  10. Redis中的简单事物以及消息订阅发布