2.1 Window下环境搭建java
2.1.1 安装Javaweb
2.1.2 安装Eclipse浏览器
(网上资源不少,就不详将了)。eclipse
2.1.3 下载Java版的Selenium包。学习
下载地址:http://docs.seleniumhq.org/download/spa
提供一下百度网盘下载地址: http://pan.baidu.com/share/link?shareid=1233226792&uk=375774229firefox
2.1.4 建立第一个Java程序code
eclipse导入selenium的全部jar包。blog
简单步骤“ip
——》
——》
——》
——》
2.2 编写第一个自动化脚本
package com.cy.selenium; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class Test01 { public static void main(String[] args) { System.out.println("start selenium"); WebDriver driver=new FirefoxDriver();// 用WebDriver new Firefox浏览器的驱动给变量driver,至关于driver拿到了Firefox浏览器的控制权。 // driver.manage().window().maximize(); driver.get("https://www.baidu.com/"); driver.findElement(By.id("kw")).sendKeys("selenium2 java"); driver.findElement(By.id("su")).click(); try { driver.wait(2000); } catch (InterruptedException e) { e.printStackTrace(); }finally { driver.close(); } } }
运行这段代码,就会出现效果了。(Fiefox浏览器默认安装到C盘)。
还有一些问题多是你的浏览器不兼容的问题。
这里个人selenium2.45,火狐使用的是36的版本。
浏览器没有安装在C盘的话,使用 System的setProperty()方法指定浏览器的路径,eg:
System.setProperty("webdriver.firefox.bin", "D:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
我原本就是学习java的。