一.下载selenium java包
登录到http://docs.seleniumhq.org/download/选择“java”并download
解压压缩包
二.安装JDK,eclipse
导入选择项目-右键-build path ->add external jars 导入解压的selenium-java-2.53.0.jar,selenium-java-2.53.0-srcs.jar
新建test测试脚本- Run as->java application 执行后:百度将被打开,并输入"测试"->“百度一下”
package te; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.*; public class Test { public static void main(String[] args) { //由于使用谷歌浏览器,需要下载谷歌驱动,并指定路径 System.setProperty("webdriver.chrome.driver", "C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe"); WebDriver driver = new ChromeDriver(); driver.get("http://www.baidu.com/"); driver.manage().window().maximize(); WebElement txtbox = driver.findElement(By.name("wd")); txtbox.sendKeys("测试"); WebElement btn = driver.findElement(By.id("su")); btn.click(); driver.close(); } }