Java+Selenium环境搭建

初学者---简单的selenium环境搭建:

1. 安装JAVA环境

2.下载eclipse

3.下载firefox (不要最高版本,容易出现selenium不兼容问题)

4. 下载selenium需要的jar包下载地址:http://pan.baidu.com/s/1gdVqOAf

5. 打开eclipse,创建一个javaproject,如下截图:

测试代码如下:

package demo;

import java.io.File;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.WebDriver.Navigation;

import org.openqa.selenium.firefox.FirefoxDriver;

public class FrieFoxDriverTest {
public static void main(String[] args) {

// TODO Auto-generated method stub
System.out.println("start firefox browser...");
//如果火狐浏览器没有默认安装在C盘,需要制定其路径
System.setProperty("webdriver.firefox.bin","D:/Program Files (x86)/Mozilla Firefox/firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");

System.out.println("start firefox browser succeed...");
// 获取页面元素
WebElement input = driver.findElement(By.id("kw"));
WebElement button = driver.findElement(By.id("su"));

// 搜索Claudia值
input.sendKeys("Claudia博客");

button.click();
}

}

原文地址:https://www.cnblogs.com/claudia/p/Claudia.html