package test.seleniumTest;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import bsh.commands.dir;
public class AutoTest1 {
public static void main(String[] args) {
System.out.println("----------init------------");
// System.setProperty("webdriver.ie.driver", "E:/Test/selenium/IEDriverServer.exe");
System.setProperty("webdriver.chrome.driver", "E:/Test/selenium/chromedriver.exe");
// 创建一个 ChromeDriver 的接口,用于连接 Chrome,
//必须要有chromedriver.exe文件,selenium默认不能启动chrome
// 创建一个 Chrome 的浏览器实例
WebDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com");
WebElement element = driver.findElement(By.xpath("//*[@id='kw']"));
// WebElement element = driver.findElement(By.name("q"));
element.sendKeys("hello selenium");
WebElement element1 = driver.findElement(By.xpath("//*[@id='su']"));
element1.click();
//等待,超时则抛出错误
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//关闭所有webdriver进程,退出
driver.quit();
System.out.println("----------end------------");
}
}