import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import java.io.File;
public class Test{
public static void main(String[] args) {
// 加载相应的驱动,第二个参数是驱动路径
System.setProperty("webdriver.chrome.driver","src/test/chromedriver.exe");
WebDriver driver = new ChromeDriver();
// 放大窗口
driver.manage().window().maximize();
// 访问www.baidu.com
driver.get("https://www.baidu.com");
// 获取输入框,并输入hello Test
driver.findElement(By.id("kw")).sendKeys("hello Test");
// 点击”搜索“按钮
driver.findElement(By.id("su")).click();
try {
Thread.sleep(3000);
}catch (InterruptedException i){
i.printStackTrace();
};
driver.close();
}
}
When writing this, you must first add it to the pom file
<dependencies>
<!-- selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.4.0</version>
</dependency>
</dependencies>
Let the pom load first, the loading time is a bit long, about 10 minutes.
The other is to get a driver
https://pan.baidu.com/s/1n1xm90iy4Un5zFNooDiZsg Extraction code: whyy
put this driver in, it's fine , originally I thought the browser version should correspond to this driver, I also downloaded I found the corresponding low version of Google Chrome and found that the high version can also be used. My google version