DEV Community

Deepikandas
Deepikandas

Posted on

Selenium Execution Flow (Simple Step-by-Step)

  1. You run your Java program

You click Run in Eclipse / IntelliJ.

WebDriver driver = new ChromeDriver();
driver.get("https://example.com");

πŸ‘‰ Execution starts from the main() method.

βš™οΈ 2. Selenium starts ChromeDriver
Selenium locates the ChromeDriver executable
ChromeDriver starts as a separate server process
A new Chrome browser opens

πŸ‘‰ Now 3 things exist:

Your Java code
ChromeDriver (middle layer)
Chrome browser
🌐 3. A browser session is created

ChromeDriver creates a session like:

Session ID: 12345
Browser: Chrome
Status: Active

πŸ‘‰ This session is used for all communication

πŸ”— 4. Selenium sends commands to browser

Example:

driver.get("https://example.com");

This is converted into a request:

Open URL β†’ https://example.com

Sent like:

Java β†’ ChromeDriver β†’ Chrome browser
🌍 5. Browser loads the webpage

Chrome does:

Downloads HTML
Downloads CSS + JS
Builds DOM (Document Object Model)
Renders UI on screen

πŸ‘‰ Now you SEE the page

🌳 6. DOM is created in memory

Example:

Login

Becomes:

A DOM node inside browser memory
πŸ€– 7. Selenium finds elements (WebElement creation)

Example:

WebElement btn = driver.findElement(By.id("login"));

What happens:

Selenium asks ChromeDriver:
πŸ‘‰ β€œFind element with id = login”
ChromeDriver searches DOM
Returns matching node

πŸ‘‰ Selenium gets a WebElement reference

πŸ–±οΈ 8. You perform actions

Example:

btn.click();

Flow:

Selenium β†’ ChromeDriver β†’ Browser β†’ DOM click event

Browser then:

Executes click
Runs JS (if any)
Updates UI if needed
πŸ” 9. Each command repeats same cycle

Example:

driver.findElement(By.id("user")).sendKeys("admin");
driver.findElement(By.id("pass")).sendKeys("1234");
driver.findElement(By.id("login")).click();

Each step:

πŸ‘‰ Find element β†’ Send command β†’ Browser executes β†’ Response

🧹 10. Closing browser
driver.quit();

What happens:

All tabs close
ChromeDriver session ends
Memory is released


Why WebDriver is called a Client–Server Model

Because Selenium and the browser do NOT talk directly. Instead, they communicate through a structured request–response system, just like a client and a server.

🧠 Simple Definition

πŸ‘‰ Selenium WebDriver follows a client–server architecture where:

Client (Selenium code) sends requests
Server (Browser Driver + Browser) processes them
Response is sent back to the client
🧩 Who is Client and who is Server?
πŸ”Ή Client Side

πŸ‘‰ Your Selenium test code

Example:

driver.findElement(By.id("login")).click();

βœ” This is the request generator

πŸ”Ή Server Side (Two layers)

  1. ChromeDriver (Server bridge) Receives commands from Selenium Translates them into browser-understandable actions
  2. Chrome Browser (execution server) Actually performs actions Works with: Blink (rendering engine) V8 (JavaScript engine) πŸ” How communication happens CLIENT (Selenium Code) ↓ HTTP Request SERVER (ChromeDriver) ↓ Internal Commands BROWSER (Chrome) ↓ DOM / UI updated ↓ HTTP Response CLIENT (Selenium Code) πŸ“‘ Why HTTP communication?

Selenium uses:

W3C WebDriver Protocol (JSON over HTTP)

Example request:

POST /session/{id}/element
{
"using": "id",
"value": "login"
}

πŸ‘‰ ChromeDriver reads it and acts on the browser

🧠 Why this design?

  1. Language independence 🌍 Client can be Java, Python, C#, JS Server (browser driver) understands standard protocol
  2. Browser independence 🌐 Same client works with: ChromeDriver GeckoDriver (Firefox) EdgeDriver

Top comments (0)