SoftwareTestPilot

Beginner · Certificate included

Selenium WebDriver Fundamentals

8 practical lessons in 45 minutes: how WebDriver works, your first Java test, reliable locators, explicit waits, frames, windows and alerts, the Page Object Model, TestNG assertions and data-driven tests, and a small framework project you can show in interviews.

8 lessons45 minCertificate+90 points
01

Lesson 1 of 86 min read

How Selenium WebDriver really works

Selenium WebDriver lets code control a real browser: open pages, click, type and read what is on screen. Knowing what happens between your code and the browser explains most errors you will see later, and it is a favourite first interview question.

Key takeaways

  1. 1Selenium is a family of tools: WebDriver (code controls the browser), Selenium Grid (run tests on many machines/browsers in parallel) and Selenium IDE (a record-and-playback browser extension). Jobs mean WebDriver.
  2. 2Flow: your test (Java, Python, C#, JS) -> Selenium client library -> W3C WebDriver protocol (HTTP + JSON) -> browser driver (chromedriver, geckodriver, msedgedriver) -> the real browser.
  3. 3Since Selenium 4.6, Selenium Manager downloads the right driver automatically. You no longer need WebDriverManager or System.setProperty for most setups.
  4. 4WebDriver is an interface; ChromeDriver, FirefoxDriver and EdgeDriver are classes that implement it. Writing WebDriver driver = new ChromeDriver() lets you swap browsers easily.
  5. 5Selenium only drives browsers. Assertions come from TestNG or JUnit, reports from Allure or Extent, and builds from Maven or Gradle.

One click, step by step

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

1. Java client sends HTTP POST /session/{id}/element {"using":"css selector","value":"#login"} 2. chromedriver asks Chrome to find the element -> returns an element id 3. Client sends POST /session/{id}/element/{elementId}/click 4. Chrome clicks; chromedriver returns 200 OK If step 2 finds nothing -> NoSuchElementException If the page re-rendered between 2 and 3 -> StaleElementReferenceException

Go deeper

Expert notes beyond the basics

4 topics
  1. 01

    Selenium 3 vs Selenium 4: what actually changed

    Selenium 3 used the JSON Wire Protocol, so commands were translated twice and browsers behaved slightly differently. Selenium 4 speaks the W3C WebDriver standard directly, which browsers implement natively, so behaviour is more consistent. Selenium 4 also added relative locators (above, below, near), switchTo().newWindow(), element screenshots, better Grid with a Docker-friendly design, Chrome DevTools Protocol access for things like network throttling, and Selenium Manager (4.6+) for automatic driver downloads. In interviews, saying 'W3C protocol and Selenium Manager' shows you are current.

  2. 02

    Why so many exceptions? Reading them like a tester

    NoSuchElementException: the locator matched nothing at that moment (wrong locator, wrong frame, or page not ready). StaleElementReferenceException: you found the element, then the page re-rendered, so your reference is old; find it again. ElementClickInterceptedException: another element (cookie banner, overlay, sticky header) is on top. ElementNotInteractableException: it exists but is hidden or disabled. TimeoutException: an explicit wait's condition never became true. SessionNotCreatedException: browser and driver versions don't match. Each name points directly to the cause.

  3. 03

    Selenium vs Playwright vs Cypress: an honest view

    Selenium supports the most languages (Java, Python, C#, JS, Ruby) and every major browser, and has a huge job market, especially in Indian service companies and banks with Java stacks. Playwright and Cypress have built-in auto-waiting and nicer debugging, so beginners write stable tests faster. Many companies run large existing Selenium suites and will for years. Learning Selenium well (waits, POM, TestNG) transfers directly to any tool. Don't argue which is 'best' in an interview; explain trade-offs.

  4. 04

    Where Selenium Grid fits

    Grid runs your tests on remote machines. Your code uses new RemoteWebDriver(new URL(gridUrl), options) instead of new ChromeDriver(). The Grid hub routes each session to a node with the requested browser. Teams use it, or cloud services like BrowserStack and Sauce Labs that expose the same interface, to run hundreds of tests in parallel on many browsers and operating systems. Running Grid locally is one docker compose file with the official selenium images.

Common mistakes to avoid

  • - Saying 'Selenium can test desktop apps or APIs'. It only automates web browsers; APIs need REST Assured or Postman, desktop needs other tools.
  • - Still adding System.setProperty and old WebDriverManager code to Selenium 4.6+ projects 'because the tutorial did'. Selenium Manager handles drivers now.
  • - Declaring ChromeDriver driver = new ChromeDriver() everywhere, which locks your code to one browser instead of using the WebDriver interface.
  • - Ignoring the exception name and immediately adding a sleep. The exception usually tells you the real cause.

Try it yourself

Without running code, predict the exception for each: (1) a locator with a typo; (2) you click a product, the list refreshes, then you click a saved element from the old list; (3) a cookie banner covers the Login button; (4) Chrome updated to v130 but an old pinned chromedriver v120 is used.

Write your answer on paper or in a sheet first, then compare.

Interview questions

How to answer like a confident QA engineer

4 questions
  1. Q1

    Explain Selenium WebDriver architecture.

    Model answer

    My test code uses the Selenium client library for my language. Each command is converted to a W3C WebDriver protocol request (HTTP with JSON) and sent to a browser-specific driver such as chromedriver. The driver translates it into native browser commands, the browser performs the action and the response travels back. In Selenium 4 the W3C protocol is the standard, so behaviour is consistent across browsers, and Selenium Manager handles driver downloads.

  2. Q2

    Can Selenium handle CAPTCHA or OTP?

    Model answer

    Not reliably, and it shouldn't. CAPTCHA exists to block automation. In test environments we ask developers to disable CAPTCHA or use test keys, and for OTP we use a fixed test OTP, a test SMS/email inbox API or read it from the database. Solving CAPTCHA in automation defeats its purpose.

  3. Q3

    What are the limitations of Selenium?

    Model answer

    Web browsers only; no built-in reporting, assertions or test runner (we add TestNG/JUnit and Allure); no auto-waiting, so synchronisation is our job; cannot handle CAPTCHA, image comparison or Windows file dialogs directly; and needs coding skill. Most limits are solved by combining it with other tools.

  4. Q4

    What is the difference between findElement and findElements?

    Model answer

    findElement returns the first matching WebElement and throws NoSuchElementException if nothing matches. findElements returns a List, which is empty if nothing matches and never throws. I use findElements(...).isEmpty() to check that something is absent, such as an error message that should not appear.

Knowledge check

+5 points

What does chromedriver do?

Student reviews

–

Loading…

– enrolled

  • 0%
  • 0%
  • 0%
  • 0%
  • 0%

Sign in and complete 20% of the course to leave a review.

Loading reviews…