</>

Technology

Selenium

Difficulty

Beginner

Interview Question

What will happen in the background when you execute new FirefoxDriver()?

new FirefoxDriver() triggers the Firefox binary, opens the browser with default options, and creates a FirefoxDriver object connected via geckodriver.

Answer

What Happens When You Execute new FirefoxDriver()

When you call new FirefoxDriver(), the following sequence happens in the background:

Step-by-step execution:

  1. geckodriver is located — Selenium finds the geckodriver executable via System.setProperty("webdriver.gecko.driver", "path/to/geckodriver")

  2. geckodriver process starts — A new geckodriver process is launched on a local port (e.g., 4444 or random)

  3. Firefox binary is triggered — geckodriver launches the Firefox browser executable with default options

  4. New browser window opens — A fresh Firefox browser window appears with no extensions, no cookies, no history (clean profile)

  5. FirefoxDriver object is created — Java creates a FirefoxDriver instance that holds a connection to this browser via the WebDriver protocol (W3C JSON Wire Protocol)

  6. Session is established — A unique session ID is created, allowing commands to be routed to that specific browser instance

Code sequence:

Java
System.setProperty("webdriver.gecko.driver", "C://Drivers/geckodriver.exe");
// Step 1: Points to geckodriver binary

WebDriver driver = new FirefoxDriver();
// Steps 2-6: geckodriver launches → Firefox opens → connection established

driver.get("https://example.com");
// HTTP command sent via geckodriver to Firefox

Architecture:

CODE
Java Test ←→ geckodriver ←→ Firefox Browser
(sends W3C commands) (translates to Marionette protocol)

Summary:

  • Firefox binary is triggered
  • Firefox browser opens with default options
  • FirefoxDriver object is created and connected to the browser
  • The driver is ready to receive commands

Follow AutomateQA

Related Topics