Selenium Interview Questions & Answers
These are the Selenium questions that come up most often in automation testing and SDET interviews. Each answer is short enough to revise quickly, with Java code for the questions where interviewers expect you to write syntax, and a link to the full tutorial. For the complete learning path, start with The Complete Selenium WebDriver Guide.
Selenium Fundamentals (Q1–8)
Q1. What is Selenium WebDriver?
An open-source library for automating web browsers. Test code sends commands through browser-specific drivers (ChromeDriver, GeckoDriver, EdgeDriver, SafariDriver) using the W3C WebDriver protocol.
Learn more: Selenium WebDriver Fundamentals
Q2. Why is Selenium so popular?
It's free and open source, supports Chrome, Firefox, Edge and Safari, has official bindings for Java, Python, C#, JavaScript and Ruby, is a W3C standard implemented by browser vendors, and has a huge community and ecosystem.
Q3. What are Selenium's limitations?
Web applications only (no desktop apps — use Appium for mobile), no built-in test runner or reporting, no API testing, no CAPTCHA or OTP automation by design, and OS-level dialogs and image/video validation need other tools.
Q4. Explain the Selenium WebDriver architecture.
Test script → client library (language binding) → browser driver → browser. In Selenium 4 each command is sent as a W3C WebDriver protocol request (JSON over HTTP); Selenium 3 used the older JSON Wire Protocol.
Learn more: Fundamentals
Q5. Is WebDriver a class or an interface?
An interface. WebDriver driver = new ChromeDriver(); is upcasting: an interface reference to a browser-specific implementation, so the same code works for any browser.
Q6. What is WebDriver's super interface?
SearchContext, which declares findElement() and findElements(). WebElement also extends it, which is why you can search inside an element.
Q7. What is the difference between Selenium RC and WebDriver?
Selenium RC injected JavaScript into the browser through a proxy server and was slow. WebDriver controls the browser directly through drivers — faster, more realistic and no server needed.
Q8. What's new in Selenium 4?
The W3C WebDriver protocol, relative locators (above, below, near…), a new window/tab API (driver.switchTo().newWindow()), Chrome DevTools access, a rebuilt Grid, and Selenium Manager for automatic driver setup.
Learn more: Selenium Manager and driver versions
Locators & XPath (Q9–15)
Q9. What locator strategies does Selenium support?
Eight: id, name, className, tagName, linkText, partialLinkText, cssSelector and xpath.
Learn more: Locators & XPath
Q10. What is the By class?
A class with static methods (By.id(), By.xpath()…) that create locator objects passed to findElement(). Storing By objects in page objects, instead of WebElements, also prevents stale elements.
Q11. Absolute vs relative XPath — which should you use?
Absolute XPath starts from the root (/html/body/div[2]/…) and breaks when any wrapper changes. Relative XPath starts with // and anchors to meaningful attributes or text. Always prefer relative — it's far more maintainable; the speed difference is negligible in practice.
Learn more: Absolute vs Relative XPath
Q12. What are XPath axes?
Ways to move through the DOM relative to a known element: parent, child, ancestor, descendant, following-sibling, preceding-sibling, following, preceding.
By.xpath("//td[text()='Ravi']/following-sibling::td[1]") // the cell next to "Ravi"
Practise with 150+ locator exercises with solutions.
Q13. How do you locate dynamic elements?
Anchor to the stable part: starts-with() or contains() in XPath (or ^=/*= in CSS), another stable attribute, or a nearby label using axes — combined with explicit waits.
By.cssSelector("input[id^='user_']")
By.xpath("//label[text()='Email']/following-sibling::input")
Q14. How do you handle duplicate IDs or multiple matches?
Make the locator more specific (scope it to a container, add attributes), or use findElements() and pick the right one — for example the visible one — rather than relying on index positions that change.
Q15. CSS selectors vs XPath?
CSS is concise and readable; XPath can match by text and navigate in any direction with axes. Classic CSS can't select a parent, though modern browsers support :has(). Use CSS for attributes and classes, XPath when you need text or DOM navigation.
Commands & WebElements (Q16–21)
Q16. What is the difference between get() and navigate().to()?
Both open a URL and wait for the page load. navigate() also offers back(), forward() and refresh().
Learn more: WebElement & Browser Commands
Q17. findElement() vs findElements()?
findElement() returns the first match or throws NoSuchElementException. findElements() returns a list — empty if nothing matches — so it's the right way to check whether an optional element exists.
Q18. close() vs quit()?
close() closes the current window; quit() closes all windows and ends the session. Use quit() in teardown.
Q19. How do you count the links on a page?
int links = driver.findElements(By.tagName("a")).size();
Q20. What do isDisplayed(), isEnabled() and isSelected() check?
Visibility, enabled state (e.g. a disabled button), and selection state (checkboxes, radio buttons, options).
Q21. How do you get an element's text, attribute, size or CSS value?
getText(), getAttribute() (or getDomAttribute()/getDomProperty() in Selenium 4), getSize(), getLocation() and getCssValue("color").
Waits & Synchronisation (Q22–26) ⭐
Q22. How is synchronisation achieved in Selenium?
With implicit, explicit and fluent waits — preferably explicit waits for specific conditions.
Learn more: Selenium Waits
Q23. Implicit vs explicit wait?
An implicit wait is global: every findElement polls up to the timeout. An explicit wait waits for a specific condition on a specific element:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.id("submit"))).click();
Don't mix them — combined, timeouts become unpredictable. See Implicit vs Explicit vs Fluent Wait.
Q24. What is FluentWait?
A configurable wait where you set the timeout, the polling interval and which exceptions to ignore while waiting. WebDriverWait is actually a subclass of FluentWait with sensible defaults (500 ms polling, ignoring NoSuchElementException).
Q25. Why avoid Thread.sleep()?
It always waits the full time, even when the page is ready, making suites slow — and it's tuned to one machine's speed, so it still fails on slower CI agents.
Q26. How do you handle page loading?
Selenium waits for the page load with get() by default; set a limit with driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30)). For AJAX-driven content, wait for a condition that proves the content is ready.
Forms, Alerts, Frames & Windows (Q27–33)
Q27. How do you handle dropdowns?
Select country = new Select(driver.findElement(By.id("country")));
country.selectByVisibleText("India"); // or selectByValue("IN"), selectByIndex(2)
String selected = country.getFirstSelectedOption().getText();
The Select class only works on <select> elements; custom dropdowns are clicked like normal elements.
Learn more: Form Elements
Q28. How do you handle multi-select dropdowns?
Check isMultiple(), select several options, read them with getAllSelectedOptions(), and clear with deselectAll().
Q29. How do you verify a checkbox or radio button is selected?
element.isSelected() — click only if it isn't already in the state you need.
Q30. How do you handle JavaScript alerts?
Alert alert = new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.alertIsPresent());
String message = alert.getText();
alert.accept(); // or dismiss(); sendKeys("text") for prompts
Learn more: Alerts, Frames & Windows
Q31. How do you handle frames?
Switch in by index, name/id or element — ideally with frameToBeAvailableAndSwitchToIt — and return with driver.switchTo().defaultContent() (or parentFrame() for nested frames).
Q32. How do you handle multiple windows or tabs?
String original = driver.getWindowHandle();
driver.findElement(By.linkText("Open report")).click();
for (String handle : driver.getWindowHandles()) {
if (!handle.equals(original)) {
driver.switchTo().window(handle);
}
}
// ... work in the new tab ...
driver.close();
driver.switchTo().window(original);
Q33. How do you handle SSL certificate warnings?
ChromeOptions options = new ChromeOptions();
options.setAcceptInsecureCerts(true);
WebDriver driver = new ChromeDriver(options);
Actions & JavaScriptExecutor (Q34–39)
Q34. How do you right-click, double-click or hover?
Actions actions = new Actions(driver);
actions.contextClick(element).perform(); // right-click
actions.doubleClick(element).perform();
actions.moveToElement(menu).click(subMenuItem).perform(); // hover, then click
Learn more: Selenium Actions Class
Q35. build() vs perform()?
build() compiles a sequence of actions; perform() executes it. In Selenium 4, perform() builds internally, so build().perform() and perform() behave the same.
Q36. How do you drag and drop?
actions.dragAndDrop(source, target).perform(); — or clickAndHold(source).moveToElement(target).release().perform() when an app needs the individual steps.
Q37. What is JavascriptExecutor?
An interface for running JavaScript in the browser — useful for scrolling or reading values Selenium can't reach directly:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("arguments[0].scrollIntoView({block:'center'});", element);
Use JavaScript clicks sparingly — they bypass what a real user can do.
Learn more: JavaScriptExecutor & Typecasting
Q38. What is upcasting in Selenium?
Assigning a browser class to the WebDriver interface type (WebDriver driver = new FirefoxDriver();). Casting back to another interface — (JavascriptExecutor) driver — works because the driver class implements it.
Q39. How do you take a screenshot?
File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
Files.copy(src.toPath(), Paths.get("target", "failure.png"));
// Selenium 4: element.getScreenshotAs(OutputType.FILE) for one element
Advanced Handling (Q40–43)
Q40. How do you upload a file?
Send the absolute file path to the <input type="file"> element — no dialog needed:
driver.findElement(By.cssSelector("input[type='file']"))
.sendKeys(new File("src/test/resources/resume.pdf").getAbsolutePath());
Only native OS dialogs need tools such as AutoIt or the Robot class.
Learn more: Advanced Element Handling
Q41. How do you find broken links?
Collect every href, send an HTTP request to each, and flag status codes of 400 or above:
for (WebElement link : driver.findElements(By.tagName("a"))) {
String url = link.getAttribute("href");
if (url == null || !url.startsWith("http")) {
continue;
}
HttpURLConnection conn =
(HttpURLConnection) URI.create(url).toURL().openConnection();
conn.setRequestMethod("HEAD");
if (conn.getResponseCode() >= 400) {
System.out.println("Broken: " + url);
}
conn.disconnect();
}
Some servers reject HEAD — retry those with GET before reporting them.
Q42. How do you handle AJAX controls?
Wait for the condition that proves the data arrived — a row count, visible text, a spinner disappearing — with an explicit wait, never a fixed delay.
Q43. How do you work with dynamic web tables?
Find the row by a value you know, then move to the cell you need — no hard-coded row numbers:
String role = driver.findElement(
By.xpath("//table[@id='users']//tr[td[text()='Asha']]/td[2]"))
.getText();
TestNG, Grid & Maven (Q44–47)
Q44. Which TestNG annotations do you use?
@Test, @BeforeMethod/@AfterMethod (browser setup and teardown), @BeforeClass/@AfterClass, @BeforeSuite/@AfterSuite (reports, config) and @DataProvider for data-driven tests.
Learn more: TestNG Essentials · TestNG Cheat Sheet
Q45. Hard assert vs soft assert?
A hard Assert stops the test at the first failure. SoftAssert records failures and continues — and you must call assertAll() at the end, or failures are silently ignored.
SoftAssert soft = new SoftAssert();
soft.assertEquals(title, "Dashboard");
soft.assertTrue(logo.isDisplayed());
soft.assertAll(); // reports every failure
Q46. How do you run tests in parallel?
Set parallel="methods" (or classes/tests) and thread-count in testng.xml, and keep one driver per thread with ThreadLocal<WebDriver> so threads don't share a browser.
Learn more: Parallel, Grid & Cross-Browser
Q47. What is Selenium Grid?
A way to run tests on many browsers and machines in parallel. Tests connect with RemoteWebDriver to the Grid URL. Selenium 4 Grid can run as a single standalone server, in hub-and-node mode, or fully distributed — and is often run in Docker.
See the Docker + Selenium Grid Guide.
Framework & Project (Q48–50)
Q48. What is the Page Object Model?
A design pattern where each page is a class holding its locators and actions; tests call page methods instead of Selenium commands. It removes duplication and localises changes when the UI changes.
Learn more: Frameworks & POM
Q49. What is Apache POI used for?
Reading and writing Excel files for data-driven testing — typically feeding a TestNG @DataProvider.
Learn more: Data-Driven Testing
Q50. What challenges have you faced in Selenium projects?
Answer with real examples, each with its fix: dynamic elements (stable locators), synchronisation (explicit waits), flaky tests in CI (window size, test data, CI differences), stale elements (By locators), and test data management. Interviewers care more about how you solved it than the list.
Learn more: Project, Process & Estimation
How to Prepare
- Be able to write Q23, Q27, Q30, Q32, Q34 and Q43 from memory — they're the most common "write it now" questions.
- Prepare two real stories for Q50, with the problem, what you tried and the result.
- Practise scenario questions in Selenium Scenario-Based Questions, and take a timed round in the Selenium Interview Simulator.
- For errors, know the common exceptions and their fixes.
Next Steps
- The Complete Selenium WebDriver Guide
- Java Coding Programs for Interview — for the coding round
- Explain Your Automation Framework
- The Complete SDET Interview Guide
From Real Projects
In interviews for testing and automation roles, I've found the questions come back to real work: the application you tested, how you wrote and reviewed test cases, how you tracked execution and defects (for me, TestRail and Jira), and how your automation was structured (Selenium, Java, TestNG, POM and a business library). Prepare one short, honest example from your own projects for each topic on this page. Testing Testsigma — a platform where users write automated tests in plain English — meant thinking like its users, who are testers themselves. For each answer, add one sentence about where you used it in a real project — interviewers remember examples, not definitions.
📚 Official documentation: Selenium documentation