Prev Next

Testing / Selenium Interview questions

1. What is Selenium? 2. What are the components of the Selenium suite? 3. What are the supported browsers in Selenium? 4. What are the supported programming languages in Selenium WebDriver? 5. How do you install Selenium WebDriver in a Java project? 6. What is Selenium WebDriver? 7. What are locators in Selenium? 8. How do you use the By class in Selenium? 9. Define implicit wait in Selenium? 10. Describe the Selenium IDE? 11. List the different types of waits in Selenium? 12. How do you take a screenshot in Selenium WebDriver? 13. What is a WebElement in Selenium? 14. How do you launch a browser using Selenium WebDriver? 15. What are assertions in Selenium? 16. What is the difference between findElement and findElements in Selenium? 17. How does Selenium handle multiple windows and tabs? 18. What is the difference between driver.close() and driver.quit()? 19. How do you handle iframes in Selenium? 20. What is the difference between implicit wait and explicit wait? 21. How does Selenium's WebDriverWait work with ExpectedConditions? 22. What is the purpose of Selenium Grid? 23. How do you handle dropdowns in Selenium using the Select class? 24. What is the difference between XPath and CSS selectors? 25. How do you run tests in parallel using TestNG and Selenium? 26. What is the difference between @BeforeMethod and @BeforeClass in TestNG? 27. How do you handle file uploads in Selenium? 28. How do you handle browser cookies in Selenium? 29. What is the difference between Thread.sleep() and WebDriverWait? 30. How do you generate test reports in Selenium (e.g., with ExtentReports)? 31. What is the difference between headless and headed mode in Selenium? 32. How do you debug a failing Selenium test? 33. What is the JavascriptExecutor in Selenium? 34. How do you handle dynamic web elements in Selenium? 35. What is the difference between Selenium's Actions class and native WebElement methods? 36. Explain the internal working of Selenium WebDriver? 37. Explain the execution flow of a Selenium test? 38. Why did Selenium 4 move to the W3C WebDriver protocol? 39. When should you use Selenium Grid over local execution? 40. How can you optimize Selenium test execution time? 41. How do you troubleshoot a StaleElementReferenceException in Selenium? 42. Explain the architecture of Selenium Grid 4? 43. What happens when a Selenium locator doesn't match any element? 44. How does Selenium implement browser automation without a built-in interception mechanism (network mocking limitations)? 45. Why doesn't Selenium provide auto-waiting like modern frameworks? 46. How do you implement the Page Object Model with PageFactory in Selenium? 47. What is the difference between Selenium Grid's Hub-Node model and the new Router-Distributor model? 48. How does Selenium handle elements inside Shadow DOM? 49. Explain the internal working of Selenium's explicit wait polling mechanism? 50. How can you integrate Selenium tests into a CI/CD pipeline?

1. What is Selenium?

Selenium is a free, open-source suite of tools for automating web browsers, originally created in 2004 and now one of the most widely used frameworks for browser-based testing and automation. Rather than being a single product, it's a collection of related tools - WebDriver for programmatic brows...

Read full answer

2. What are the components of the Selenium suite?

The Selenium project bundles several distinct tools, each aimed at a different part of browser automation. Selenium WebDriver - the core API for programmatically controlling a real browser from test code. Selenium IDE - a browser extension for recording and replaying interactions without writing ...

Read full answer

3. What are the supported browsers in Selenium?

Selenium WebDriver can automate any browser that ships a compatible driver implementing the W3C WebDriver protocol. Browser Driver Chrome / Chromium-based Edge ChromeDriver / EdgeDriver Firefox GeckoDriver Safari SafariDriver (built into macOS) Each browser vendor maintains its own driver executa...

Read full answer

4. What are the supported programming languages in Selenium WebDriver?

Selenium WebDriver provides official client bindings for four languages, all built against the same underlying W3C WebDriver protocol. Java - historically the most common, often paired with TestNG or JUnit. Python - the selenium PyPI package, commonly paired with pytest. C# - used with NUnit or M...

Read full answer

5. How do you install Selenium WebDriver in a Java project?

In a Maven-based Java project, Selenium is added as a dependency in pom.xml rather than a manual JAR download: org.seleniumhq.selenium selenium-java 4.24.0 Since Selenium 4.6, there's no need to separa...

Read full answer

6. What is Selenium WebDriver?

Selenium WebDriver is the core API of the Selenium suite - a set of language bindings and a protocol for controlling a browser as if a real user were interacting with it, without going through any browser plugin or injected JavaScript layer. WebDriver driver = new ChromeDriver(); driver.get("http...

Read full answer

7. What are locators in Selenium?

Locators are the strategies Selenium uses to find a specific element on a page so an action or check can be performed on it, exposed through the By class. driver.findElement(By.id("username")); driver.findElement(By.name("email")); driver.findElement(By.cssSelector(".btn-primary")); driver.findEl...

Read full answer

8. How do you use the By class in Selenium?

By is a static factory class whose methods each build a locator strategy that findElement() or findElements() can then use to search the DOM. WebElement login = driver.findElement(By.id("login-btn")); List rows = driver.findElements(By.cssSelector("table tr")); WebElement link = drive...

Read full answer

9. Define implicit wait in Selenium?

An implicit wait tells the WebDriver instance to poll the DOM for a set duration whenever a findElement() call doesn't immediately find a match, before throwing a NoSuchElementException . driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10)); It's set once per driver instance and then...

Read full answer

10. Describe the Selenium IDE?

Selenium IDE is a browser extension (available for Chrome and Firefox) that records user interactions - clicks, typing, navigation - directly in the browser and turns them into a replayable test script, without requiring any code to be written by hand. Recorded tests can be exported into real sou...

Read full answer

11. List the different types of waits in Selenium?

Selenium provides three distinct waiting mechanisms, each suited to a different situation. Wait type Behavior Implicit wait Global polling timeout applied to every findElement call Explicit wait Targeted wait for a specific condition on a specific element Fluent wait Explicit wait with configurab...

Read full answer

12. How do you take a screenshot in Selenium WebDriver?

WebDriver instances that implement the TakesScreenshot interface can capture the current browser view as an image file. File src = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); FileUtils.copyFile(src, new File("screenshot.png")); This captures only the visible viewport by default, ...

Read full answer

13. What is a WebElement in Selenium?

A WebElement is Selenium's representation of a single DOM node, returned by findElement() , and it's the object interactions like .click() , .sendKeys() , and .getText() are called on. WebElement email = driver.findElement(By.id( "email" )); email.sendKeys( "user@example.com" ); System.out.printl...

Read full answer

14. How do you launch a browser using Selenium WebDriver?

Launching a browser means instantiating the driver class for that browser, which starts the matching driver executable and opens a fresh browser session. WebDriver driver = new ChromeDriver(); driver.get("https://example.com"); // ... test steps ... driver.quit(); Browser-specific Options classes...

Read full answer

15. What are assertions in Selenium?

Selenium itself has no built-in assertion library - it only provides ways to read state from the page ( getText() , isDisplayed() , getAttribute() ), so assertions come from whatever test framework Selenium is paired with, like JUnit, TestNG, or AssertJ. Assert.assertEquals(driver.getTitle(), "Da...

Read full answer

16. What is the difference between findElement and findElements in Selenium?

Both search the DOM using a By locator, but they differ in what they return and how they fail. findElement findElements Returns a single WebElement Returns a List Throws NoSuchElementException if nothing matches Returns an empty list if nothing matches Use when you expect exactly one ...

Read full answer

17. How does Selenium handle multiple windows and tabs?

Selenium tracks open browser windows/tabs by string handles, and driver.getWindowHandle() returns the handle for the currently focused one, while driver.getWindowHandles() returns the handles of all open windows in that session. String original = driver.getWindowHandle(); driver.findElement(By.li...

Read full answer

18. What is the difference between driver.close() and driver.quit()?

These sound similar but operate at very different scopes. driver.close() driver.quit() Closes only the currently focused window/tab Closes all windows opened by this session The driver session stays alive if other windows remain Terminates the entire WebDriver session and driver process Used when...

Read full answer

19. How do you handle iframes in Selenium?

Elements inside an iframe are not part of the main document's accessible DOM from WebDriver's perspective, so you must explicitly switch context into the frame before locating anything inside it. driver.switchTo().frame("payment-frame"); driver.findElement(By.id("card-number")).sendKeys("42424242...

Read full answer

20. What is the difference between implicit wait and explicit wait?

Both exist to handle timing, but they operate at different scopes and with different precision. Implicit wait Explicit wait Set once, applies globally to all findElement calls Applied per-condition, on a specific element/step Only waits for element presence in the DOM Can wait for visibility, cli...

Read full answer

21. How does Selenium's WebDriverWait work with ExpectedConditions?

WebDriverWait repeatedly polls a supplied condition, defined via the ExpectedConditions utility class, until it returns a truthy result or the configured timeout elapses. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement btn = wait.until( ExpectedConditions.elemen...

Read full answer

22. What is the purpose of Selenium Grid?

Selenium Grid distributes test execution across multiple machines and browser/OS combinations, so a suite can run in parallel remotely instead of sequentially on one local machine. WebDriver driver = new RemoteWebDriver( new URL( "http://grid-hub:4444" ), new ChromeOptions() ); A test written aga...

Read full answer

23. How do you handle dropdowns in Selenium using the Select class?

For a native HTML element, Selenium can set the file path directly with sendKeys() , without needing to interact with the operating system's native file picker dialog at all. WebElement upload = driver.findElement(By.id("resume-upload")); upload.sendKeys("/absolute/path/to/resume...

Read full answer

28. How do you handle browser cookies in Selenium?

The Options interface (via driver.manage() ) exposes methods to read, add, and remove cookies for the current domain. Cookie sessionCookie = new Cookie("session_id", "abc123"); driver.manage().addCookie(sessionCookie); Set all = driver.manage().getCookies(); driver.manage().deleteCookie(s...

Read full answer

29. What is the difference between Thread.sleep() and WebDriverWait?

Both pause execution, but for fundamentally different reasons and with very different reliability. Thread.sleep() WebDriverWait Fixed, unconditional pause Polls a condition, exits as soon as it's true Wastes time if the app is ready sooner Only waits as long as actually necessary Still fails if t...

Read full answer

30. How do you generate test reports in Selenium (e.g., with ExtentReports)?

Selenium itself has no reporting layer, so reports typically come from a separate library like ExtentReports, hooked into the test framework's lifecycle listeners. ExtentReports extent = new ExtentReports(); ExtentSparkReporter spark = new ExtentSparkReporter("report.html"); extent.attachReporter...

Read full answer

31. What is the difference between headless and headed mode in Selenium?

These control whether the automated browser renders a visible UI window during execution. Headless Headed No visible browser window Full visible browser window Lower resource usage, common on CI Higher overhead, common for local debugging Enabled via browser Options arguments Default when no head...

Read full answer

32. How do you debug a failing Selenium test?

Since Selenium has no built-in Inspector or trace viewer like some newer frameworks, debugging typically combines a few complementary techniques. Running in headed mode locally lets you visually watch what the browser actually does at the failing step, rather than reasoning about it purely from s...

Read full answer

33. What is the JavascriptExecutor in Selenium?

JavascriptExecutor is an interface that lets Selenium execute arbitrary JavaScript directly in the context of the current page, for situations the standard WebDriver API can't handle cleanly on its own. JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("arguments[0].scrollInto...

Read full answer

34. How do you handle dynamic web elements in Selenium?

Because findElement resolves immediately rather than lazily, dynamic content generally needs an explicit wait for the right condition before interacting with it, rather than relying on a fixed pause. WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement row = wait.unt...

Read full answer

35. What is the difference between Selenium's Actions class and native WebElement methods?

Native WebElement methods like .click() and .sendKeys() perform simple, single interactions. The Actions class builds up a chain of low-level input events - mouse moves, button presses, key holds - for interactions that a single method call can't express. Native methods Actions class .click(), .s...

Read full answer

36. Explain the internal working of Selenium WebDriver?

When test code calls a WebDriver method, the language binding serializes it into an HTTP request following the W3C WebDriver protocol and sends it to a locally running driver executable (ChromeDriver, GeckoDriver, etc.) over a local port. sequenceDiagram participant T as Test Script participant C...

Read full answer

37. Explain the execution flow of a Selenium test?

A typical Selenium test run moves through setup, execution, and teardown phases, usually orchestrated by the paired test framework rather than Selenium itself. flowchart TD A[Test framework starts test method] --> B[Instantiate WebDriver, launch driver executable] B --> C[Browser session opens] C...

Read full answer

38. Why did Selenium 4 move to the W3C WebDriver protocol?

Prior to Selenium 4, WebDriver communicated using the JSON Wire Protocol, a Selenium-project-specific format that predated any official browser vendor standard - meaning every browser vendor had to reverse-engineer or specifically support a Selenium-defined format rather than an independently gov...

Read full answer

39. When should you use Selenium Grid over local execution?

Local execution is simplest when a suite is small enough to finish quickly on one machine and only needs to validate against one or two browsers a developer already has installed. Selenium Grid becomes worthwhile once any of these apply: the suite needs true cross-browser coverage (Chrome, Firefo...

Read full answer

40. How can you optimize Selenium test execution time?

Several practical changes compound to meaningfully cut down suite runtime. Replace implicit waits with targeted explicit waits , since a blanket implicit wait adds delay to every failed lookup across the whole suite. Run in parallel via TestNG/JUnit with a ThreadLocal WebDriver, rather than execu...

Read full answer

41. How do you troubleshoot a StaleElementReferenceException in Selenium?

This exception means a previously found WebElement no longer refers to a live DOM node - usually because the page (or a portion of it, in a single-page app) re-rendered after the element was located. The fix is almost always to re-locate the element fresh right before using it again, rather than ...

Read full answer

42. Explain the architecture of Selenium Grid 4?

Selenium Grid 4 was rebuilt around a set of composable components communicating over events, replacing the older monolithic Hub/Node model with independently scalable pieces. flowchart LR A[New Session Request] --> B[Router] B --> C[Distributor] C --> D[Session Queue] C --> E[Node 1] C --> F[Node...

Read full answer

43. What happens when a Selenium locator doesn't match any element?

The behavior differs depending on which lookup method is used and what waits are configured. With no implicit or explicit wait set, findElement() checks the DOM exactly once and throws NoSuchElementException immediately if nothing matches - there's no retry at all in that bare case. With an impli...

Read full answer

44. How does Selenium implement browser automation without a built-in interception mechanism (network mocking limitations)?

Classic Selenium WebDriver has no native way to intercept or mock network requests the way newer frameworks do - the W3C WebDriver protocol it's built on was designed around controlling the browser's UI and DOM, not its network layer. Teams needing network mocking with Selenium typically reach fo...

Read full answer

45. Why doesn't Selenium provide auto-waiting like modern frameworks?

Selenium's core API predates the "auto-waiting locator" design popularized by newer tools by well over a decade, and it was built on top of the WebDriver protocol's model of discrete, synchronous commands rather than a lazy, retrying query abstraction layered on top of them. Adding true auto-wait...

Read full answer

46. How do you implement the Page Object Model with PageFactory in Selenium?

The Page Object Model wraps a page's elements and interactions in a class; PageFactory is Selenium's built-in helper for initializing those elements using annotations instead of manual findElement calls in a constructor. public class LoginPage { WebDriver driver; @FindBy (id = "email" ) WebElemen...

Read full answer

47. What is the difference between Selenium Grid's Hub-Node model and the new Router-Distributor model?

Selenium 3's Grid used a single centralized Hub that both accepted incoming test requests and directly tracked every registered Node's capacity - one component doing both routing and capacity management. Hub-Node (Grid 3) Router-Distributor (Grid 4) Single Hub handles routing and capacity trackin...

Read full answer

48. How does Selenium handle elements inside Shadow DOM?

Unlike Playwright's locators, Selenium's classic By strategies do not automatically pierce shadow roots - a plain CSS selector or XPath simply cannot see past a shadow boundary into its contents. WebElement host = driver.findElement(By.cssSelector("custom-element")); SearchContext shadowRoot = ho...

Read full answer

49. Explain the internal working of Selenium's explicit wait polling mechanism?

WebDriverWait is built on a lower-level FluentWait , which runs a loop that repeatedly invokes the supplied condition function against the driver, sleeping for a fixed polling interval (500ms by default) between each attempt. flowchart TD A[wait.until condition called] --> B[Evaluate condition fu...

Read full answer

50. How can you integrate Selenium tests into a CI/CD pipeline?

Because Selenium needs a real browser and matching driver, most CI setups either run tests headless on the CI runner directly, or point RemoteWebDriver at a containerized Selenium Grid so the pipeline doesn't depend on whatever browser happens to be preinstalled on the build agent. # GitHub Actio...

Read full answer

«
»
API

Comments & Discussions