Selenium Practical Exercises
Reading about Selenium doesn't make you job-ready — automating real pages does. This roadmap gives you 34 hands-on exercises in 7 levels, from launching a browser to designing a framework, each linked to a detailed practice set. Do them in order; tick them off as you go.
Before You Start
- Setup: Java 17+, Maven, an IDE, and a project with
selenium-javaandtestng. Selenium 4.6+ downloads browser drivers automatically (Selenium Manager) — no WebDriverManager or driver paths needed. - Practice sites: the NavTutorial Automation Practice Hub, Selenium's own web form, The Internet (alerts, frames, uploads, dynamic content), SauceDemo (e-commerce flow), DemoQA and the OrangeHRM demo (tables, forms).
- Don't automate live commercial sites such as Amazon — it breaks their terms and bot protection makes tests fail unpredictably.
Your Starter Test (Runnable)
Exercises 1 and 15 in one test — launch a browser, fill a form, wait properly and assert:
import java.time.Duration;
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.*;
import org.testng.Assert;
import org.testng.annotations.*;
public class StarterTest {
private WebDriver driver;
@BeforeMethod
public void setUp() {
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@Test
public void submitWebForm() {
driver.get("https://www.selenium.dev/selenium/web/web-form.html");
Assert.assertEquals(driver.getTitle(), "Web form");
driver.findElement(By.name("my-text")).sendKeys("Selenium practice");
driver.findElement(By.cssSelector("button")).click();
WebElement message = new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.visibilityOfElementLocated(By.id("message")));
Assert.assertEquals(message.getText(), "Received!");
}
@AfterMethod
public void tearDown() {
if (driver != null) driver.quit();
}
}
Run it with mvn test. Every exercise below follows the same pattern: locate, act, wait for a condition, assert.
See it step by step in the Selenium WebDriver Visualizer.
Level 1 — Selenium Basics (Exercises 1–6)
- Launch and verify. Open Chrome, maximize, open a URL, assert the title, then
quit(). Repeat for Firefox and Edge; explainclose()vsquit(). - Locate a login form three ways — by
id/name, CSS selector and relative XPath. - Dynamic IDs. Locate fields whose IDs change using
starts-with(),contains()or CSS^=. - XPath functions and axes. Use
text(), AND/OR,following-sibling,parentandancestoron a table. - Validate an error message after a failed login with
getText(). - Element states. Assert a button is enabled/disabled and a checkbox is selected with
isEnabled(),isSelected(),isDisplayed().
Practice sets:
Theory:
Level 2 — Common UI Controls (Exercises 7–14)
- Text boxes. Type, clear, read the typed value with
getAttribute("value"), check placeholders and disabled fields. - Checkboxes and radio buttons. Select one and many, verify default selections, and check that radio buttons are mutually exclusive.
- Registration form. Fill a complete form — text, radio, checkboxes, dropdown — and submit.
- Standard dropdowns ⭐. Use
Selectby visible text, value and index; handle multi-select. - Custom dropdowns. Handle Bootstrap/React dropdowns that aren't
<select>elements, including dynamic suggestions. - Alerts. Accept, dismiss and type into prompt alerts; wait with
alertIsPresent(). - Frames. Switch by index, name/ID and element; handle nested frames and return with
defaultContent(). - Windows and tabs. Switch parent → child → parent, close only the child, open a new tab with
switchTo().newWindow().
Practice sets:
Level 3 — Synchronization and Interactions (Exercises 15–19)
- Explicit waits ⭐. Wait for visible, clickable and invisible (spinner gone). Then remove every
Thread.sleep()from your earlier exercises. - AJAX and page readiness. Wait for content loaded after page load — a table row count, a URL change or text appearing.
- Mouse actions. Hover menus, right-click and double-click with the
Actionsclass. - Drag, slide and type. Drag and drop, move a slider, and use keyboard keys (
Keys.ENTER,Keys.TAB, key combinations). - JavaScriptExecutor. Scroll to an element, scroll the page, and read values through JavaScript — and explain when a JS click is (and isn't) acceptable.
Practice sets:
Theory:
Level 4 — Real-World Scenarios (Exercises 20–25)
- Upload and download. Upload with
sendKeys()on<input type="file">; verify a downloaded file exists in a configured download folder. Know when Robot/AutoIt are needed (native OS dialogs only). - Web tables ⭐. Read all rows, and find the employee whose salary is greater than ₹50,000 by looping through rows — no hard-coded row numbers.
- Paginated tables. Search for a record across pages, clicking "Next" until it's found or the last page is reached.
- Date pickers. Select today's, a past and a future date, navigating months with a loop guard.
- Broken links. Collect every
href, request each one and report status codes ≥ 400. - Tooltips and shadow DOM. Read a tooltip after hover; locate an element inside a shadow root with
getShadowRoot().
Theory: Advanced Element Handling.
Level 5 — Framework Design (Exercises 26–30)
- Page Object Model. Convert your login and form tests into page classes with
Bylocators (and try@FindBywith PageFactory to compare). - TestNG. Use setup/teardown annotations, groups (smoke/regression), priorities,
dependsOnMethodsand a@DataProvider. - Data-driven tests. Read test data from Excel (Apache POI), a properties file and JSON.
- Maven and logging. Run suites with
mvn testthrough Surefire, and log to console and file with Log4j2. - Reports and screenshots. Generate an Extent or Allure report; capture timestamped screenshots on failure with a TestNG listener.
Theory:
Level 6 — CI/CD and Scale (Exercises 31–33)
- Jenkins. Push your framework to Git and create a Jenkins pipeline that runs smoke tests on every push and regression nightly, publishing reports.
- Cross-browser and parallel. Run the suite on Chrome, Firefox and Edge in parallel through testng.xml, with a ThreadLocal driver and headless mode.
- Grid and retries. Run tests on Selenium Grid (Docker) with
RemoteWebDriver; add a RetryAnalyzer and re-runtestng-failed.xml.
Theory:
Level 7 — Interview-Ready (Exercise 34)
-
Build a framework from scratch and defend it. BaseTest, DriverFactory, page objects, utilities, config layer, listeners, reporting and CI — published on GitHub with a README. Then practice explaining how it handles dynamic elements, flaky tests, slow runs, browser crashes and environment downtime, and why CAPTCHA and OTP aren't automated (test environments disable or bypass them).
Guides:
Suggested Pace
| Levels | Beginner | With some experience |
|---|---|---|
| 1–2 | 2–3 weeks | 1 week |
| 3–4 | 2–3 weeks | 1 week |
| 5 | 2–3 weeks | 1–2 weeks |
| 6–7 | 2 weeks | 1 week |
From Real Projects
In my automation roles I created, modified and enhanced Selenium WebDriver scripts in Java, organized with POM classes and a business library, and ran them with TestNG on Chrome and Firefox. Exercises like these build exactly the muscle memory you need when a real application — for me, Canolog's sales, inventory and service screens — throws a new kind of element at you. Do the exercises in order; each part assumes the skills from the previous one.
FAQs
How is this roadmap organized?
34 numbered exercises in 7 levels, from browser basics to framework design and CI/CD, each linked to a detailed practice set.
Where should beginners start?
With the starter test above and Level 1 — browser launch, locators and element actions.
Which exercises matter most for interviews?
Explicit waits (15), dropdowns (10), web tables (21), Page Object Model (26), TestNG (27), parallel runs (32) and the framework exercise (34). See also: Top 50 Selenium Interview Questions & Answers.
What should experienced testers focus on?
Levels 4–7: dynamic tables, shadow DOM, framework architecture, CI/CD, Grid and parallel execution, and explaining design decisions.
Which websites are best for practice?
The NavTutorial Practice Hub, Selenium's web form, The Internet, SauceDemo, DemoQA and the OrangeHRM demo — all built for automation practice.
Do I still need WebDriverManager?
No. Since Selenium 4.6, Selenium Manager downloads the right driver automatically.