We use cookies to analyze site traffic and show personalized ads. You can accept all cookies or decline personalized advertising.
Learn more in our Privacy Policy.
Create a Maven project and add Selenium dependency for automation.
Maven makes managing dependencies incredibly simple. Instead of manually downloading JAR files and adding them to your project, you just declare what you need in pom.xml, and Maven handles the rest.
Learning to add Selenium through Maven is the industry-standard approach for test automation projects. This ensures:
Before starting, make sure you have:
JAVA_HOME configured.MAVEN_HOME and PATH configured.pom.xml file at the root.org.seleniumhq.selenium).selenium-java).4.38.0).selenium-basics (or any name you prefer).com.dotlog.student (example).selenium-basics (example).com.company.project). For learning projects, you can use something like com.dotlog.student.After the project is created, you'll see a pom.xml file in the project root.
pom.xml in IntelliJ.<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dotlog.student</groupId>
<artifactId>selenium-basics</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
</properties>
<dependencies>
<!-- We will add Selenium here -->
</dependencies>
</project>This file contains all project configurations and dependencies. The <dependencies> section is where we'll add Selenium.
The snippet should look like this:
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.38.0</version>
</dependency>pom.xml.<dependencies> tag.Your pom.xml should now look like this:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dotlog.student</groupId>
<artifactId>selenium-basics</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.38.0</version>
</dependency>
</dependencies>
</project>pom.xml → Maven → Reload project.Let's quickly verify that Selenium is installed correctly.
src/main/java folder.SeleniumCheck and click OK.import org.openqa.selenium.WebDriver;
public class SeleniumCheck {
public static void main(String[] args) {
System.out.println("Selenium is ready!");
}
}If IntelliJ auto-completes the import without errors, Selenium is properly installed!
SeleniumCheck class to confirm there are no runtime errors. You should see "Selenium is ready!" printed in the console.Here's what a complete pom.xml should look like after adding Selenium:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.dotlog.student</groupId>
<artifactId>selenium-basics</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.38.0</version>
</dependency>
</dependencies>
</project><properties> section for easier management across multiple dependencies.<dependencies></dependencies> tags to work correctly.