一. 安装驱动管理
<dependency>
<groupId>io.github.bonigarcia</groupId>
<artifactId>webdrivermanager</artifactId>
<version>5.8.0</version>
<scope>test</scope>
</dependency>
二. 安装selenium库
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.0.0</version>
</dependency>
三. 使用selenium编写代码(举例)
public void example_test()
{
//驱动程序管理的⾃动化
WebDriverManager. chromedriver ().setup();
ChromeOptions options = new ChromeOptions();
//允许访问所有链接
options.addArguments("--remote-allow-origins=*");
//1、打开浏览器
WebDriver driver = new ChromeDriver(options);
//2.输⼊百度⽹址:https://www.baidu.com
driver.get("https://www.baidu.com");
//3、找到输⼊框并输⼊“迪丽热巴”
driver.findElement(By.xpath("//*[@id=\"kw\"]")).sendKeys("迪丽热巴");
//4、找到“百度⼀下”按钮并点击
driver.findElement(By.xpath("//*[@id=\"su\"]")).click();
//5、关闭浏览器
driver.quit();
}