版本firefox41.0.2
Selenium2.48.2
代码下载地址:http://pan.baidu.com/s/15JaFG
关键代码如下:
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.bj58.webdriver.demo</groupId>
<artifactId>webdriverdemo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>webdriverdemo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.48.2</version>
</dependency>
</dependencies>
</project>
test.java
package com.bj58.webdriver.demo.webdriverdemo;
import java.util.concurrent.TimeUnit;
import junit.framework.TestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class WebDriverDemoTest {
WebDriver driver;
@Before
public void setUp() throws Exception {
System.out.println("init...");
//用 Chrome
// System.setProperty(
// "webdriver.chrome.driver",
// "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");
// driver = new ChromeDriver();
// 如果火狐浏览器没有默认安装在C盘,需要制定其路径
System.setProperty("webdriver.firefox.bin",
"E:\\tools\\迅雷\\Mozilla Firefox\\firefox.exe");
driver = new FirefoxDriver();
//用 IE
// driver = new InternetExplorerDriver();
}
@Test
public void testTest() throws Exception {
// driver.get("http://www.baidu.com/");
driver.get("http://www.baidu.com/");
// driver.manage().window()
WebElement txtbox = driver.findElement(By.name("wd"));
txtbox.sendKeys("Glen");
WebElement btn = driver.findElement(By.id("su"));
btn.click();
for(int i=0;i<100;i++){
txtbox = driver.findElement(By.name("wd"));
txtbox.clear();
txtbox.sendKeys(i+"");
btn.click();
Thread.sleep(3000);
}
// driver.close();
}
}
//Browser Selenium IDE Selenium 1 (RC) Operating Systems
//Firefox 3.x Record and playback tests Start browser, run tests Windows, Linux, Mac
//Firefox 3 Record and playback tests Start browser, run tests Windows, Linux, Mac
//Firefox 2 Record and playback tests Start browser, run tests Windows, Linux, Mac
//IE 8 Test execution only via Selenium RC* Start browser, run tests Windows
//IE 7 Test execution only via Selenium RC* Start browser, run tests Windows
//IE 6 Test execution only via Selenium RC* Start browser, run tests Windows
//Safari 4 Test execution only via Selenium RC Start browser, run tests Windows, Mac
//Safari 3 Test execution only via Selenium RC Start browser, run tests Windows, Mac
//Safari 2 Test execution only via Selenium RC Start browser, run tests Windows, Mac
//Opera 10 Test execution only via Selenium RC Start browser, run tests Windows, Linux, Mac
//Opera 9 Test execution only via Selenium RC Start browser, run tests Windows, Linux, Mac
//Opera 8 Test execution only via Selenium RC Start browser, run tests Windows, Linux, Mac
//Google Chrome Test execution only via Selenium RC Start browser, run tests Windows, Linux, Mac
//Others Test execution only via Selenium RC Partial support possible** As a