What Selenium interviews check
Selenium WebDriver has been around long enough that interviewers assume you know the API. What they probe is judgement: can you write a locator that survives the next release, can you synchronise with the page without Thread.sleep, and can you structure a suite so that a hundred tests do not repeat the same login code? This lab is built around those three skills, in Java, the language most Selenium frameworks still use.
XPath and CSS practice against real HTML
The locator challenges give you a page fixture and a target element. You write a By strategy (By.id, By.name, By.className, By.cssSelector, By.xpath or By.linkText), and the lab resolves it with the same XPath and CSS engines a browser uses, then shows what matched. A locator must match the target exactly: matching it plus a hidden duplicate counts as a failure, as it would cause a flaky test.
Start with choosing between id and CSS and counting elements with findElements, then move to the two patterns interviews ask about most: locating a button whose id is generated, where //button[normalize-space()='Submit order'] finds it by visible text instead of an id that changes every build, and following-sibling navigation, where you read a value by its label, as in //th[normalize-space()='Status']/following-sibling::td[1], without relying on row positions.
Waits, frames, windows and framework code
The Java challenges cover the situations that make Selenium suites flaky. The canonical explicit wait looks like new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(By.id("submit"))).click();. Do not combine it with a non-zero implicit wait: the two interact unpredictably and can multiply timeouts, which is why the Selenium documentation warns against mixing them.
- Synchronisation: explicit waits and recovering from stale elements.
- Browser context: switching into an iframe, handling multiple windows and JavaScript alerts.
- Framework design: driver lifecycle, the Page Object Model, TestNG DataProvider and RemoteWebDriver with Selenium Grid.
How the Java challenges are checked
Running arbitrary Java and real browsers needs an isolated execution service, which SDETRole does not operate. So the Java code challenges are validated against pattern checks: each check tests for one specific practice, such as using WebDriverWait instead of Thread.sleep or switching back with defaultContent(). They are not compiled or executed, and each check says what it looks for. The locator challenges, by contrast, are resolved for real.
Use the lab alongside the Selenium WebDriver basics lesson and the Selenium interview questions, where the model answers explain the architecture behind each pattern.
Frequently asked questions
What is Selenium WebDriver?
Selenium WebDriver is an open-source library for automating real browsers. Your test code, written in Java, Python, C#, JavaScript or Ruby, sends commands through the W3C WebDriver protocol to a browser driver such as chromedriver or geckodriver, which controls Chrome, Firefox, Edge or Safari. It automates browsers but is not a test framework, so it is usually combined with TestNG, JUnit or pytest, plus Selenium Grid for running tests in parallel across machines.
How can I practise Selenium online?
Use this lab. Locator challenges resolve your By strategy (id, name, className, cssSelector, xpath, linkText) against a real page fixture in your browser, using the same CSS and XPath engines a browser uses. Java code challenges cover waits, iframes, windows, alerts, page objects and Grid, and are checked with pattern rules rather than compiled. Pair it with the XPath and CSS selector tester to try selectors on your own HTML.
What are the most common Selenium interview questions?
Expect WebDriver architecture; locator strategies and XPath axes; implicit, explicit and fluent waits; handling StaleElementReferenceException; switching to iframes, windows and alerts; the Page Object Model; data-driven tests with a TestNG DataProvider; parallel runs with ThreadLocal drivers; and Selenium Grid 4. Senior roles add framework design and migrating a suite to Playwright. Each has a worked answer in the Selenium interview questions.
What is the difference between implicit wait and explicit wait?
An implicit wait is a global setting: every findElement call polls up to the timeout for the element to exist. An explicit wait targets one condition, for example new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(button)), and can wait for visibility, clickability, text or a custom condition. Prefer explicit waits and keep the implicit wait at zero, because mixing the two can produce unpredictable wait times. See Selenium waits explained.
How do I handle dynamic elements in Selenium?
Dynamic elements have IDs or classes that change on every load, such as id='btn-48213'. Anchor on something stable instead: a data-testid, a name, label text, or a partial match like //button[starts-with(@id,'btn-')] or [id^='btn-']. Use XPath axes to find an element relative to a stable neighbour, and pair the locator with an explicit wait for visibility or clickability. Practise on the dynamic ID XPath challenge.
What is Page Object Model in Selenium?
The Page Object Model is a design pattern where each page or component has a class that holds its locators and exposes user actions, such as loginPage.signIn(user, password). Tests call those methods instead of using locators directly, so when the UI changes you update one class rather than every test. Keep assertions in tests, return the next page object from navigation methods, and avoid giant catch-all page classes. Try the Page Object Model challenge.
How do I handle StaleElementReferenceException?
The exception means an element you found earlier is no longer attached to the DOM, usually because the page or a component re-rendered after you located it. Locate the element again just before using it, wait for the re-render to finish (for example ExpectedConditions.stalenessOf(oldElement) followed by a fresh find), and keep By locators in page objects instead of caching WebElement references. Blind retries hide the cause. Practise in the stale element challenge.
Is Selenium still relevant in 2026?
Yes. Selenium is still widely used in enterprise test suites, it is built on the W3C WebDriver standard that browser vendors support, and it keeps evolving: Selenium 4 added relative locators, a redesigned Grid and WebDriver BiDi support. Many new projects choose Playwright, so knowing both is useful. Selenium's concepts (locators, synchronisation, page objects, grids) transfer directly, and job listings in Java-heavy organisations still ask for it.
Is XPath or CSS better for Selenium?
Prefer a stable id or name, then CSS for structure and attributes because it is shorter and widely understood. Use XPath when you need to match on text or move to a parent or sibling, which CSS cannot do.
Why are the Java challenges not executed?
Compiling Java and driving a real browser requires a sandboxed execution service. Until one is available, Java challenges are checked with pattern rules and say so; locator challenges are resolved against real HTML.