<dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.8.1</version> </dependency> <dependency> <groupId>com.google.guava</groupId> <artifactId>guava</artifactId> <version>23.0</version> </dependency> <dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.2</version> </dependency>
package worms; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class ChromeWorm { public static void main(String[] args) { System.setProperty("webdriver.chrome.bin", "C:/Users/AppData/Local/Google/Chrome/Application/chrome.exe"); System.setProperty("webdriver.chrome.driver", "C:/Users/AppData/Local/Google/Chrome/Application/chromedriver.exe"); //chromedriver.exe的安装路径 //设置Webdriver启动chrome为默认用户的配置信息(包括书签、扩展程序等) ChromeOptions options = new ChromeOptions(); options.addArguments("user-data-dir=C:/Users/AppData/Local/Google/Chrome/User Data"); //第一步chrome://version/中的对应信息 WebDriver driver = new ChromeDriver(options); driver.manage().window().maximize();//窗口最大化 driver.get("https://blog.csdn.net");//打开测试地址 } }