An Ultimate step-by-step guide for beginners to setup Selenium WebDriver quickly.
After understanding Selenium architecture and its components, the next step is setting up Selenium WebDriver. A proper Selenium WebDriver setup is essential for creating and running automation scripts efficiently. In this guide, you will learn how to set up Selenium WebDriver using Java, Maven, and IntelliJ IDEA. By the end of this tutorial, you will execute your first Selenium automation script.
Prerequisites
Before starting Selenium WebDriver setup, ensure you have:
- Java JDK installed (Java 11 or higher recommended)
- IntelliJ IDEA or Eclipse IDE
- Maven installed
- Internet connection for dependency downloads
You can verify Java installation by running:
java -version
Example output:
java version "17.0.9"
Step 1: Install IntelliJ IDEA
IntelliJ IDEA is one of the most popular IDEs for Selenium automation.
Download IntelliJ IDEA
Download Community Edition and install it.
After installation:
- Open IntelliJ IDEA.
- Select New Project.
- Choose Maven as the project type.
Step 2: Create a Maven Project
A Maven project helps manage dependencies automatically.
Project structure:
SeleniumDemo│├── src│ ├── main│ └── test│├── pom.xml│└── target
Maven uses the pom.xml file to download required libraries.
Step 3: Add Selenium Dependency
Open the pom.xml file and add the Selenium dependency:
<dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>4.34.0</version> </dependency></dependencies>
Save the file.
Maven automatically downloads the required Selenium libraries.
Step 4: Create Your First Test Class
Inside the src/test/java folder, create:
FirstTest.java
Example:
public class FirstTest {}
Step 5: Launch Chrome Browser
Import Selenium packages:
import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;
Initialize ChromeDriver:
WebDriver driver = new ChromeDriver();
Selenium Manager in Selenium 4 automatically downloads and manages the ChromeDriver.
Step 6: Open a Website
Use the get() method:
driver.get("https://www.google.com");
Complete example:
import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;public class FirstTest { public static void main(String[] args) { WebDriver driver = new ChromeDriver(); driver.get("https://www.google.com"); }}
When executed, Chrome opens and navigates to Google.
Step 7: Maximize Browser Window
To maximize the browser:
driver.manage().window().maximize();
Example:
driver.get("https://www.google.com");driver.manage().window().maximize();
Step 8: Get Page Title
Retrieve page title:
String title = driver.getTitle();System.out.println(title);
Output:
Google
Step 9: Close Browser
Close the browser after execution:
driver.quit();
Complete example:
import org.openqa.selenium.WebDriver;import org.openqa.selenium.chrome.ChromeDriver;public class FirstTest { public static void main(String[] args) { WebDriver driver = new ChromeDriver(); driver.get("https://www.google.com"); driver.manage().window().maximize(); System.out.println(driver.getTitle()); driver.quit(); }}
Project Structure Example
A typical Selenium project structure looks like:
SeleniumFramework│├── src│ ├── main│ └── test│├── pom.xml├── target└── test-output
As your framework grows, you can organize:
- Pages
- Tests
- Utilities
- Reports
- Configuration files
How Selenium Manager Simplifies Driver Setup
Before Selenium 4, users manually downloaded:
- ChromeDriver
- GeckoDriver
- EdgeDriver
And configured:
System.setProperty("webdriver.chrome.driver","C:\\drivers\\chromedriver.exe");
With Selenium Manager, this step is no longer necessary.
Simply write:
WebDriver driver = new ChromeDriver();
Selenium automatically manages compatible browser drivers.
Common Setup Errors
Java Not Installed
Error:
java command not found
Solution:
Install JDK and configure the PATH variable.
Maven Dependency Not Downloaded
Solution:
Refresh Maven project:
Right Click Project↓Maven↓Reload Project
Browser Version Mismatch
Update Chrome browser and Selenium dependencies.
Missing Imports
Press:
Alt + Enter
IntelliJ automatically imports missing classes.
Best Practices
Follow these best practices:
- Use Maven for dependency management.
- Use Java 11 or above.
- Prefer Selenium 4.
- Keep browser versions updated.
- Close browsers using
driver.quit(). - Organize code into packages.
Frequently Asked Questions
Is ChromeDriver installation required in Selenium 4?
No.
Selenium Manager automatically downloads and manages browser drivers.
Which IDE is best for Selenium?
IntelliJ IDEA and Eclipse are the most commonly used IDEs.
Is Maven mandatory?
No.
But Maven simplifies dependency management and is highly recommended.
Which Java version should I use?
Java 11 or Java 17 are recommended.
Can I use Selenium WebDriver with Python?
Yes.
Selenium supports Java, Python, JavaScript, C#, and Ruby.
Conclusion
Setting up Selenium WebDriver is straightforward with Selenium 4 and Selenium Manager. By installing Java, creating a Maven project, and adding Selenium dependencies, you can quickly start automating web applications.
Now that your environment is ready, the next step is learning how Selenium locators work to identify web elements effectively.
Related Articles
✓ Selenium Architecture Explained
✓ Selenium Components Explained
✓ XPath Tutorial for Selenium Beginners
✓ CSS Selector vs XPath in Selenium
Discover more from Rotebit
Subscribe to get the latest posts sent to your email.

Pingback: Selenium Waits Explained - Rotebit
Pingback: Selenium Web Elements Handling Guide - Rotebit