Table of contents
①Download the Chrome browser and check the browser version
②Download and decompress the Chrome browser driver
③ Configure the Java environment
④ Put the driver file in the bin file directory of jdk
⑤Verify whether the environment is successfully built
1. Create a java (Maven) project and add dependencies in pom.xml
2. Create the Main class in the java file and write the relevant code
3. Start Main and view the Chrome browser
①Download the Chrome browser and check the browser version
Chrome browser download address: Google Chrome web browser
②Download and decompress the Chrome browser driver
Driver download address: CNPM Binaries Mirror (npmmirror.com)
Choose the same version as your Chrome on the page
After downloading, decompress and get an exe file after decompression:
③ Configure the Java environment
The configuration of the Java environment is detailed in this blogger's article; [Java SE] Java basic environment configuration and Java basic understanding In C/C++, an int may be a 16-bit integer, a 32-bit integer, or another size specified by the compiler provider. Note that before running the Java program, you must first install the JDK (JavaDevelopmentKit, Java Development Kit), which contains javac and java tools, and the Java program is finally run in the JVM (Java Virtual Machine). Then select the Path variable in the system variables, click the Edit button, add the JAVA_HOME variable you just created to the Path variable, in the pop-up edit system variable box, click New, and enter. ........... https://blog.csdn.net/m0_67995737/article/details/125963443
④ Put the driver file in the bin file directory of jdk
⑤Verify whether the environment is successfully built
1. Create a java (Maven) project and add dependencies in pom.xml
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java -->
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.141.59</version>
</dependency>
2. Create the Main class in the java file and write the relevant code
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
public class Main {
public static void main(String[] args) {
ChromeOptions options=new ChromeOptions();
options.addArguments("--remote-allow-origins=*");
WebDriver webDriver=new ChromeDriver(options);
webDriver.get("https://www.baidu.com/");
}
}
3. Start Main and view the Chrome browser
We can see that Chrome automatically opened the official website of Baidu Search. It means that our environment has been built successfully.