Interview questions · Tech stack

Selenium Interview Questions & Answers (2026)

These interviews test your grasp of Selenium architecture, locator strategies, synchronization techniques, test framework integration, and performance considerations. To succeed, master WebDriver commands, explain why you choose specific locators, demonstrate handling dynamic content, and show how you structure maintainable test suites. Highlight trade‑offs, show debugging mindset, and relate Selenium usage to CI pipelines and cross‑browser testing.

21 questions · updated Aug 29, 2026

Quick facts

Typical roundsPhone screen, technical coding, and a system design or framework integration interview.
Core language supportJava, C#, Python, JavaScript, Ruby – most questions assume Java.
Key librariesTestNG/JUnit, Maven/Gradle, Page Object Model, Selenium Grid.
Common focusLocator reliability, synchronization, and test‑suite scalability.

Questions

Beginner

What is Selenium WebDriver and how does it differ from Selenium RC?

Selenium WebDriver is a browser automation API that drives browsers natively by communicating with each browser's driver. Unlike Selenium RC, which relied on a JavaScript injection server to control the browser, WebDriver eliminates the middle‑man, resulting in faster, more reliable interactions and better support for modern browsers. Interviewers expect you to mention the architecture shift, reduced latency, and the ability to handle native events directly.

GoogleMicrosoft

Explain the difference between absolute and relative XPath. When would you prefer one over the other?

Absolute XPath starts from the root node and follows the entire DOM hierarchy, making it brittle when the UI changes. Relative XPath begins with // or .// and targets elements based on attributes or partial paths, offering more resilience. Interviewers look for you to choose relative XPath for maintainability, citing scenarios like dynamic page layouts where absolute paths break frequently.

//div[@class='product']//button[text()='Add']
Amazon

How does Selenium Grid improve test execution, and what are the main components?

Selenium Grid enables parallel test execution across multiple machines and browsers, reducing total runtime. It consists of a Hub that receives test requests and Nodes that register with the Hub to run those tests. Interviewers expect you to discuss load balancing, remote execution, and the ability to test cross‑browser compatibility simultaneously, highlighting reduced feedback cycles in CI pipelines.

IBM

What strategies can you use to reduce test flakiness caused by dynamic element IDs?

Prefer stable attributes like data-test, class names, or relative XPath that rely on surrounding static elements. Use contains() or starts-with() functions to match partial IDs, and combine with explicit waits to ensure the element is ready. Interviewers look for you to demonstrate awareness of locator robustness and the ability to adapt to generated IDs without hard‑coding them.

Spotify

What is the role of the @FindBy annotation in Selenium PageFactory?

@FindBy tells PageFactory how to locate a WebElement field, supporting lazy initialization. When PageFactory.initElements() is called, it creates proxies that locate the element only when accessed, reducing upfront overhead. Interviewers want you to explain how this improves readability, centralizes locators, and works with different locating strategies like id, css, or xpath.

Dropbox

What are the advantages of using Selenium 4's relative locators?

Relative locators let you find elements based on their position relative to other known elements (above, below, near). This reduces reliance on fragile attributes and improves readability, especially for dynamic pages where IDs change. Interviewers expect you to cite use cases like locating a button next to a label, and to note that they complement, not replace, traditional locators.

Slack

Intermediate

What are the pros and cons of using Thread.sleep() versus explicit waits?

Thread.sleep() forces a fixed pause, making tests slower and flaky when load times vary. Explicit waits (WebDriverWait with ExpectedConditions) poll the DOM until a condition is met, offering dynamic synchronization and better performance. Interviewers want you to explain that explicit waits reduce unnecessary waiting, improve reliability, and allow fine‑grained control, while Thread.sleep() should be a last resort for non‑deterministic issues.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("submit")));
Netflix

Describe the Page Object Model (POM) and its benefits in Selenium test suites.

POM separates page structure from test logic by representing each page as a class containing locators and actions. Benefits include improved readability, reusability of element definitions, easier maintenance when UI changes, and clearer abstraction for non‑technical stakeholders. Interviewers look for you to mention encapsulation, reduced duplication, and how POM integrates with test frameworks like TestNG for data‑driven testing.

public class LoginPage {
    @FindBy(id="username") private WebElement user;
    @FindBy(id="password") private WebElement pass;
    public void login(String u, String p) { user.sendKeys(u); pass.sendKeys(p); }
}
Adobe

How would you handle a dropdown that is not a standard <select> element?

For custom dropdowns, locate the container element, click to expand, then select the desired option using its visible text or index. Use explicit waits to ensure the options are loaded. Interviewers expect you to avoid the Select class, demonstrate understanding of the DOM structure, and possibly use JavaScriptExecutor for hidden elements, showing adaptability to non‑standard UI components.

WebElement dropdown = driver.findElement(By.id("customDrop"));
dropdown.click();
WebElement option = driver.findElement(By.xpath("//li[text()='Option 2']"));
option.click();
PayPal

What is the purpose of DesiredCapabilities in Selenium, and how has it evolved in recent versions?

DesiredCapabilities is a key‑value map used to configure browser settings, such as platform, version, and headless mode, before creating a driver instance. In Selenium 4, it has been superseded by Options classes (ChromeOptions, FirefoxOptions) that provide a fluent API while still supporting capability merging. Interviewers want you to discuss this evolution and show how you set capabilities for remote execution via Grid or cloud services.

ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.setCapability("acceptInsecureCerts", true);
WebDriver driver = new RemoteWebDriver(gridUrl, options);
Oracle

What is the difference between implicit and explicit waits, and why should they not be mixed?

Implicit wait sets a global timeout for locating elements, causing every findElement call to poll the DOM. Explicit wait targets specific conditions for particular elements. Mixing them can lead to unpredictable wait times because implicit wait adds latency to explicit wait polling, causing longer test execution and flaky results. Interviewers expect you to recommend using explicit waits exclusively for precise synchronization.

Uber

Explain how you would handle a modal dialog that appears after an AJAX call.

First, wait for the AJAX request to complete using ExpectedConditions.invisibilityOfElementLocated for a loading spinner. Then, wait for the modal to become visible with ExpectedConditions.visibilityOfElementLocated, and switch to it if it resides in a separate iframe. Finally, interact with the modal's elements. This shows you can coordinate asynchronous events and manage context changes reliably.

Square

Explain how you would test a file upload component using Selenium.

Locate the <input type="file"> element and send the absolute file path via sendKeys(). This bypasses the native OS dialog. After uploading, verify the file appears in the UI or that a success message is displayed. Interviewers look for you to mention handling hidden inputs, using JavaScript to make the element visible if needed, and validating post‑upload behavior.

WebElement upload = driver.findElement(By.id("fileInput"));
upload.sendKeys("C:/temp/report.pdf");
Zoom

Advanced

Explain how to capture a screenshot on test failure and embed it in a TestNG report.

Implement an @AfterMethod listener that checks ITestResult.isSuccess(). On failure, cast driver to TakesScreenshot, capture the image as a byte array, save it with a timestamped filename, and attach the path to the TestNG report using Reporter.log(). This demonstrates proactive debugging, integrates with CI dashboards, and shows you can enrich reports for faster root‑cause analysis.

if (!result.isSuccess()) {
    TakesScreenshot ts = (TakesScreenshot) driver;
    File src = ts.getScreenshotAs(OutputType.FILE);
    String path = "screenshots/" + result.getName() + ".png";
    FileUtils.copyFile(src, new File(path));
    Reporter.log("<a href='" + path + "'>Screenshot</a>");
}
Cisco

How do you manage test data for data‑driven testing in Selenium with TestNG?

Use TestNG's @DataProvider to supply test data from external sources such as CSV, Excel, or JSON. The provider reads the file, converts rows into Object arrays, and returns them. This separates data from test logic, enables parallel execution, and simplifies maintenance. Interviewers expect you to mention handling I/O exceptions, using Apache POI for Excel, and ensuring thread safety when running tests concurrently.

@DataProvider(name="loginData")
public Object[][] getData() throws IOException {
    // read CSV and return Object[][]
}
@Test(dataProvider="loginData")
public void loginTest(String user, String pass) { /* steps */ }
Shopify

What are StaleElementReferenceException and how can you prevent it?

StaleElementReferenceException occurs when an element reference becomes invalid after the DOM changes (e.g., page refresh, AJAX update). To prevent it, locate elements just before interacting, use explicit waits for visibility, or re‑fetch the element inside a retry loop. Interviewers look for you to explain the root cause, show a code pattern for retrying, and discuss why caching elements is risky in dynamic pages.

WebElement btn = driver.findElement(By.id("save"));
new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.elementToBeClickable(btn));
btn.click();
Twitter

Describe how you would implement cross‑browser testing using Selenium Grid.

Set up a Hub with a known port, register Nodes with specific browser capabilities (Chrome, Firefox, Edge) and OS combinations. In test code, define DesiredCapabilities or Options for each browser, then instantiate RemoteWebDriver pointing to the Hub URL. Use TestNG parameters or a data provider to iterate over browsers, ensuring each test runs on all configurations. Interviewers expect you to mention hub‑node communication, scalability, and handling browser‑specific quirks.

LinkedIn

How can you use JavaScriptExecutor to click an element that Selenium cannot interact with?

When an element is hidden or overlapped, Selenium's click may fail. JavaScriptExecutor can invoke the click event directly: ((JavascriptExecutor)driver).executeScript("arguments[0].click();", element); This bypasses the WebDriver's safety checks. Interviewers want you to discuss when this is appropriate, potential side effects like missing native events, and the need to verify that the action still triggers expected UI behavior.

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", driver.findElement(By.id("hiddenBtn")));
Snapchat

How do you integrate Selenium tests into a CI/CD pipeline such as Jenkins?

Create a Maven/Gradle build that compiles and runs tests with TestNG/JUnit. In Jenkins, configure a job to pull the repository, execute the build, and archive test reports and screenshots. Use headless browsers (Chrome headless) for faster execution, and optionally parallelize tests with Selenium Grid. Interviewers expect you to mention environment setup, artifact publishing, and failure notifications.

GitHub

How would you debug a test that intermittently fails due to timing issues?

First, reproduce the failure locally with increased logging. Add explicit waits around the flaky step, capture screenshots before and after the action, and use browser console logs to identify JavaScript errors. If needed, isolate the problematic element and create a small script to test its stability. Interviewers want a systematic approach showing you can pinpoint root causes and apply robust synchronization.

Airbnb

Describe how to use Selenium with Docker for isolated test environments.

Create a Dockerfile that installs a browser (Chrome/Firefox) and the Selenium server or uses the official Selenium standalone image. Mount the test code into the container, run tests with a headless driver, and output results to a shared volume. This provides consistent environments, eliminates host dependencies, and integrates easily with CI pipelines. Interviewers look for containerization benefits and basic command examples.

Reddit

Common mistakes

  • Using Thread.sleep() for synchronization instead of explicit waits.
  • Hard‑coding absolute XPaths that break with UI changes.
  • Mixing implicit and explicit waits, causing unpredictable delays.
  • Not handling stale elements after page refreshes or AJAX updates.
  • Skipping proper cleanup of driver instances, leading to orphaned browsers.

Study plan

  1. Review Selenium architecture and WebDriver commands; write simple scripts in your primary language.
  2. Master locator strategies—ID, CSS, XPath, and relative locators—by building a small POM project.
  3. Practice synchronization: implement explicit waits, avoid Thread.sleep(), and handle stale elements.
  4. Integrate tests with TestNG/JUnit, use DataProviders for data‑driven testing, and generate reports.
  5. Set up Selenium Grid or Docker containers for parallel and cross‑browser execution, then run the suite in a CI pipeline.

FAQ

Can Selenium automate mobile apps?

Selenium itself targets web browsers, but you can use Appium, which shares the WebDriver protocol, to automate native and hybrid mobile apps. The concepts of locators and waits remain the same, making the transition straightforward for Selenium‑experienced testers.

What is the best way to handle CAPTCHA in automated tests?

CAPTCHA is designed to block automation; in test environments, disable it or use test keys that return a known value. If unavoidable, you can mock the verification step or use a service that provides test‑specific tokens.

How do I run Selenium tests headlessly?

Add the "--headless" argument to ChromeOptions or FirefoxOptions. Ensure your CI environment has the necessary Xvfb or virtual display if not using native headless mode. Headless execution speeds up tests and reduces resource consumption.

Is it advisable to use Selenium for API testing?

Selenium excels at UI interaction; for API testing, tools like RestAssured or Postman are more appropriate. However, you can combine them—use Selenium for end‑to‑end flows and call APIs directly for setup or verification.

What are the limitations of Selenium with respect to modern web technologies?

Selenium cannot natively interact with PDF/Canvas elements, handle OS‑level dialogs, or test performance metrics. It also struggles with heavy single‑page applications without proper waits. Complementary tools like Cypress for front‑end or Lighthouse for performance can fill these gaps.

Related

Ready for your next interview?

Download MiPrep AI. Load your resume and the job description. Show up ready.

Free tier · No credit card · macOS 14+ · Windows 10+

Free tier · No credit card · Runs on your Mac or Windows machine