Selenium

Selenium is an open‑source automation tool used to automate web browsers. It supports multiple languages like Java, Python, C#, JavaScript, and Ruby — but Java remains the most popular choice due to its stability, community support, and compatibility with enterprise frameworks.

Selenium Components

1. Selenium WebDriver
The most commonly used component
Automates browsers by directly communicating with them
Supports Chrome, Firefox, Edge, Safari, etc.

2. Selenium IDE
A browser extension
Used for record‑and‑playback
Good for beginners but not used for real automation frameworks

3. Selenium Grid
Used for parallel execution
Runs tests across multiple machines, browsers, and OS combinations
Essential for scalable frameworks

4. Selenium RC (Deprecated)
Old version of Selenium
No longer used

Why Selenium with Java?
Strong community support
Rich ecosystem (TestNG, Maven, Jenkins, Docker, etc.)
Easy integration with frameworks
Faster execution compared to some other languages
Ideal for building enterprise‑grade automation frameworks

Prerequisites to Start Selenium with Java
Before writing your first script, ensure you have:
1. Java JDK Installed
Download from Oracle or OpenJDK.
2. IDE (Eclipse / IntelliJ IDEA)
IntelliJ is preferred for modern development.
3. Maven Project Setup
Maven helps manage dependencies.
4. Selenium Java Client Libraries
Added via Maven dependency.
5. Browser Driver (e.g., ChromeDriver)
Required for WebDriver to communicate with the browser.

Maven Dependency for Selenium

Maven Dependency
Maven Dependency
<dependencies>
   <dependency>
   <groupId>org.seleniumhq.selenium</groupId>
   <artifactId>selenium-java</artifactId>
   <version>4.21.0</version>
   </dependency>
</dependencies>
                
        
our First Selenium Java Script
Let’s automate a simple scenario:
✅ Open Chrome
✅ Navigate to Google
✅ Type “Selenium WebDriver”
✅ Click Search
✅ Print the page title
✅ Close the browser

Code Highlighting

package demo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class PageValidation {

    public static void main(String[] args) {

        // Set path to ChromeDriver (optional for latest Selenium if driver is auto-managed)
        System.setProperty("webdriver.chrome.driver", "./chromedriver.exe");

        // Launch Chrome browser
        WebDriver driver = new ChromeDriver();

        // Maximize window
        driver.manage().window().maximize();

        // Navigate to Google
        driver.get("https://designmindtech.com/");
        driver.findElement(By.linkText("DevOps")).click();
        // Locate search box
       String headerText = driver.findElement(By.xpath("//h1[@class='airinblog-css-page-title']")).getText();
       System.out.println("Header Text of the Page: "+ headerText);
        // Close browser
        driver.quit();
    }
}
    
    

How this script works?

1. Launch Browser

Code Highlighting

       WebDriver driver = new ChromeDriver();

    
2. Launch Designmindtech official site

Code Highlighting

       driver.get("https://www.google.com");

    
3. Find navigation button DevOps

Code Highlighting

    driver.findElement(By.linkText("DevOps")

    

5. Print Header Text

Code Highlighting

      String headerText = driver.findElement(By.xpath("//h1[@class='airinblog-css-page-title']")).getText();
      System.out.println("Header Text of the Page: "+ headerText);

    
6. Close Browser

Code Highlighting

     driver.quit();

    
//DesignMindTech