1、新建java工程,导入selenium-server-standalone-2.45.0.jar
我们所用的类都已封装进这个jar里了。
此版本支持 Firefox 36,如果使用测试类,启动不了火狐,建议安装火狐36.
查看火狐版本:在选项里:
2、新建类:
package
test.selenium;
import
org.openqa.selenium.By;
import
org.openqa.selenium.WebDriver;
import
org.openqa.selenium.firefox.FirefoxDriver;
public
class
Test1 {
public
static
void
main(String[] args) {
// 设置浏览器driver
WebDriver driver;
driver =
new
FirefoxDriver();
// 打开百度的首页
driver.get(
"http://www.baidu.com"
);
// 找到输入框,输入“北京博测科技”,并单击百度一下按钮
driver.findElement(By. id(
"kw"
)).clear();
driver.findElement(By. id(
"kw"
)).sendKeys(
"付华国"
);
driver.findElement(By. id(
"su"
)).click();
// 关闭浏览器
driver.close();
}
}
3、运行此类就可以看到火狐浏览器被打开,并执行搜索,完毕之后关闭。
4、第一个实例over.