环境入门——Java语言/Firefox浏览器 为例
1、搭建Java开发环境
JDK
eclipse
2、下载selenium
地址:http://docs.seleniumhq.org/download
在download页面选择Selenium Client & WebDriver Language Bindings栏相应的语言下载
解压文件,得到selenium的jar包和各种Java语言支持lib库
3、在eclipse中创建一个Java project,导入selenium-java-2.44.0.jar,并导入lib文件夹中的jar包
4、在项目中新建一个类,引入selenium包
import org.openqa.selenium.*;
import org.openqa.selenium.WebDriver.*;
import org.openqa.selenium.firefox.*;
5、写一个主函数,内容为:
System.setProperty("webdriver.firefox.bin","C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
WebDriver driver=new FirefoxDriver();
Navigation navigation = driver.navigate();
navigation.to("http://www.baidu.com");
6、运行Java程序,看到Firefox浏览器启动并打开百度首页即为成功