1.开发环境:
a:安装jdk,配置java的环境变量
b:安装eclipse 工具、火狐浏览器(低版本)
2.下载selenium包
selenium-java-2.44.0.jar
selenium-server-standalone-2.45.0.jar
selenium-java-2.44.0-srcs.jar
3.打开eclipse ,将selenium包导入
4.再编写代码
import java.sql.Time;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.server.browserlaunchers.Sleeper;
public class webdriverdemo {
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin", "D:\Program Files (x86)\Mozilla Firefox\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://www.baidu.com");
WebElement text = driver.findElement(By.name("mobile"));
text.sendKeys("百度");
Sleeper.sleepTightInSeconds(1);
text.submit();
}
}
编写完后运行,能运行访问就ok了
觉得不错的可关注微信公众号在手机上观看,让你用手机边玩边看