After installing Java, an IDE, Selenium JAR files, and browser drivers, we need to configure Selenium WebDriver in an IDE to start writing automation scripts.


1. Configuring Selenium WebDriver in Eclipse

Step 1: Create a New Java Project in Eclipse

  1. Open Eclipse IDE.
  2. Click on File β†’ New β†’ Java Project.
  3. Enter the Project Name (e.g., SeleniumProject).
  4. Click Finish.

Step 2: Add Selenium JAR Files to the Project

  1. Right-click on the project β†’ Select Properties.
  2. Go to Java Build Path β†’ Click on Libraries.
  3. Click Add External JARs... and select all downloaded Selenium .jar files.
  4. Click Apply and Close.

Step 3: Set Up Browser Driver Path in Code

To use Selenium, we need to specify the WebDriver executable path.

Example: Setting Up ChromeDriver

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class SeleniumSetup {
    public static void main(String[] args) {
        // Set the path of the ChromeDriver
        System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");

        // Launch Chrome Browser
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");

        // Print page title
        System.out.println("Page Title: " + driver.getTitle());

        // Close the browser
        driver.quit();
    }
}

2. Configuring Selenium WebDriver in IntelliJ IDEA

Step 1: Create a New Maven/Java Project

  1. Open IntelliJ IDEA β†’ Click New Project.
  2. Select Java β†’ Click Next.
  3. Enter Project Name β†’ Click Finish.

Step 2: Add Selenium Dependencies (For Maven Users)

  1. Open pom.xml file.
  2. Add the following dependencies inside <dependencies> tag:
<dependencies>
    <!-- Selenium WebDriver Dependency -->
    <dependency>
        <groupId>org.seleniumhq.selenium</groupId>
        <artifactId>selenium-java</artifactId>
        <version>4.15.0</version>
    </dependency>

    <!-- WebDriver Manager (for automatic driver setup) -->
    <dependency>
        <groupId>io.github.bonigarcia</groupId>
        <artifactId>webdrivermanager</artifactId>
        <version>5.6.0</version>
    </dependency>
</dependencies>
  1. Click on Maven β†’ Reload the Project to download dependencies.

Step 3: Run a Test Script

Use the following code to launch Chrome:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;

public class SeleniumTest {
    public static void main(String[] args) {
        // Automatically setup ChromeDriver using WebDriverManager
        WebDriverManager.chromedriver().setup();

        // Launch Chrome Browser
        WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com");

        // Print page title
        System.out.println("Page Title: " + driver.getTitle());

        // Close the browser
        driver.quit();
    }
}

3. Configuring Selenium WebDriver in VS Code

Step 1: Install Java Extension in VS Code

  • Open VS Code β†’ Go to Extensions β†’ Install Java Extension Pack.

Step 2: Add Selenium JAR Files

  • Open the project folder in VS Code.
  • Create a libs folder inside the project.
  • Copy all Selenium .jar files to the libs folder.

Step 3: Compile and Run the Selenium Script

Use the Terminal to compile and run the script:

javac -cp "libs/*" SeleniumTest.java
java -cp ".;libs/*" SeleniumTest

4. Configuring Selenium WebDriver for Different Browsers

Firefox (GeckoDriver)

System.setProperty("webdriver.gecko.driver", "C:\\path\\to\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();

Edge (EdgeDriver)

System.setProperty("webdriver.edge.driver", "C:\\path\\to\\msedgedriver.exe");
WebDriver driver = new EdgeDriver();

Safari (SafariDriver)

WebDriver driver = new SafariDriver();

(For Safari, enable Develop > Allow Remote Automation in Safari settings.)


Final Thoughts

After completing the above configuration, you are ready to automate tests using Selenium WebDriver. πŸš€

Next Steps:
βœ… Learn Basic Selenium Commands (e.g., finding elements, interacting with web pages).
βœ… Explore Selenium WebDriver Methods (e.g., click(), sendKeys(), getText()).
βœ… Implement Test Automation Frameworks (e.g., TestNG, Cucumber).

πŸ‘‰ Proceed to Selenium WebDriver Basics πŸ”₯