下载驱动地址:
https://npm.taobao.org/mirrors/chromedriver/
把驱动放置工程目录下,然后编辑代码:
package testWebdriver;
import org.apache.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class testChrome {
public static void main(String[] args) throws InterruptedException {
System.out.print("begin");
//我的谷歌是87版本 87.0.4280.66(正式版本)
String driverPath=System.getProperty("user.dir")+"/src/chromedriver.exe";
System.setProperty("webdriver.chrome.driver",driverPath);
System.setProperty("webdriver.firefox.bin", "C:/Program Files/Mozilla Firefox/firefox.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://www.baidu.com");
//窗口设定
driver.manage().window().maximize();
Thread.sleep(3000);
//log.info("开启浏览器");
driver.close();
}
}