Selenium Interview Questions & Answers

Top frequently asked interview questions with detailed answers, code examples, and expert tips.

36 Questions All Difficulty Levels Updated Mar 2026
1

What is Selenium? Easy

Selenium is an open-source automation testing tool used to automate web browsers. It allows testers and developers to simulate user interactions like clicking buttons, filling forms, navigating pages, and validating results.

Selenium supports multiple programming languages such as Java, Python, C#, and JavaScript. It works with major browsers like Chrome, Firefox, Edge, and Safari.

Important: Selenium automates only web applications, not desktop applications.
selenium basics
2

What are the components of Selenium? Easy

Selenium consists of four major components:

  • Selenium IDE - Record and playback tool.
  • Selenium WebDriver - Core automation API.
  • Selenium Grid - Run tests in parallel on multiple machines.
  • Selenium RC - Older version, now deprecated.

In real projects, WebDriver and Grid are most commonly used.

components webdriver
3

What is Selenium WebDriver? Easy

WebDriver is the main component of Selenium used to automate browser actions. It directly communicates with the browser using browser-specific drivers like ChromeDriver or GeckoDriver.

Unlike Selenium RC, WebDriver does not use JavaScript injection. It communicates using browser-native automation support.

webdriver automation
4

What is a locator in Selenium? Easy

A locator is a way to identify web elements on a page. Selenium provides multiple locator strategies:

  • id
  • name
  • className
  • tagName
  • linkText
  • partialLinkText
  • CSS Selector
  • XPath

Choosing the right locator improves stability of automation scripts.

locator xpath css
5

Difference between CSS Selector and XPath? Easy

CSS Selector is generally faster and simpler for basic element selection.

XPath is more powerful and allows navigating up and down the DOM tree.

In interviews, mention that CSS cannot move backward in DOM while XPath can.

css xpath
6

How do you launch a browser in Selenium? Easy

To launch Chrome browser in Java:

Java
WebDriver driver = new ChromeDriver();
driver.get("https://example.com");

Before launching, the appropriate browser driver must be configured.

launch browser
7

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

close() closes only the current browser window.

quit() closes all browser windows and ends the WebDriver session.

quit() is recommended in test frameworks.

browser webdriver
8

What is implicit wait? Easy

Implicit wait tells Selenium to wait for a specified time before throwing NoSuchElementException.

It applies globally to all elements.

Java
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
waits implicit
9

What is explicit wait? Easy

Explicit wait waits for a specific condition before proceeding.

Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("login")));

Explicit wait is more reliable than implicit wait.

waits explicit
10

What is Page Object Model (POM)? Easy

POM is a design pattern in Selenium where each webpage is represented as a class.

This improves maintainability, readability, and reusability of test scripts.

Interview Tip: Always mention separation of test logic and page logic.
pom design-pattern
11

How do you handle dropdowns in Selenium? Medium

Dropdowns can be handled using the Select class:

Java
Select select = new Select(driver.findElement(By.id("country")));
select.selectByVisibleText("India");

Methods available: selectByValue(), selectByIndex(), selectByVisibleText()

dropdown select
12

How do you handle alerts in Selenium? Medium

Selenium handles alerts using switchTo().alert():

Java
Alert alert = driver.switchTo().alert();
alert.accept();

Methods include accept(), dismiss(), getText(), sendKeys().

alerts webdriver
13

How do you handle frames in Selenium? Medium

To switch to frame:

Java
driver.switchTo().frame("frameName");

To come back:

driver.switchTo().defaultContent();
frames webdriver
14

How do you handle multiple windows? Medium

Use getWindowHandles() to get all window IDs.

Switch using driver.switchTo().window(windowID).

windows tabs
15

How do you take screenshot in Selenium? Medium

Screenshots can be taken using TakesScreenshot interface:

Java
File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
screenshot debugging
16

What is Selenium Grid? Medium

Selenium Grid allows running test cases in parallel across multiple machines and browsers.

It improves execution speed and supports cross-browser testing.

grid parallel
17

How do you handle dynamic elements in Selenium? Hard

Dynamic elements have changing IDs or attributes.

Best practices:

  • Use contains() in XPath
  • Use starts-with()
  • Use relative locators

Example:

//input[contains(@id,"user")]
dynamic xpath
18

How do you implement data-driven testing in Selenium? Hard

Data-driven testing separates test data from test logic.

Common methods:

  • Using Excel with Apache POI
  • Using CSV files
  • Using TestNG DataProvider
data-driven testng
19

How do you handle stale element exception? Hard

StaleElementReferenceException occurs when element is refreshed.

Solution:

  • Re-locate the element
  • Use explicit wait
  • Use retry logic
exceptions stale
20

Explain headless browser testing. Hard

Headless testing runs browser without GUI.

Useful for CI/CD pipelines.

Java
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
headless ci-cd
21

How do you integrate Selenium with Jenkins? Hard

Steps:

  1. Push code to repository
  2. Configure Jenkins job
  3. Add build step (Maven/Gradle)
  4. Run tests automatically

This enables continuous testing.

jenkins ci-cd
22

What is the difference between findElement() and findElements()? Easy

findElement() returns a single WebElement. If the element is not found, it throws NoSuchElementException.

findElements() returns a list of WebElements. If no elements are found, it returns an empty list instead of throwing an exception.

Tip: Use findElements() when validating presence of optional elements.
webelement locator
23

What are relative locators in Selenium 4? Medium

Selenium 4 introduced relative locators to locate elements based on their position relative to other elements.

Example:

Java
driver.findElement(with(By.tagName("input")).above(By.id("password")));

They improve readability but should be used carefully for stable layouts.

selenium4 locators
24

How do you handle file upload in Selenium? Medium

File upload can be handled by sending file path to input type="file".

Java
driver.findElement(By.id("upload")).sendKeys("C:\file.txt");

No need to handle OS dialog if input element is accessible.

file-upload automation
25

What is Fluent Wait in Selenium? Medium

Fluent Wait is a type of explicit wait that defines maximum wait time, polling frequency, and ignores specific exceptions.

Java
Wait wait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(20))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(NoSuchElementException.class);
waits fluent
26

How do you scroll a webpage in Selenium? Medium

Scrolling can be handled using JavaScriptExecutor.

Java
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("window.scrollBy(0,500)");

This is useful for lazy-loaded elements.

scrolling javascript
27

What is Shadow DOM and how do you handle it? Hard

Shadow DOM is used in modern web apps where elements are encapsulated inside shadow roots.

To access them, use JavaScriptExecutor:

JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement shadowRoot = (WebElement) js.executeScript("return arguments[0].shadowRoot", element);
shadow-dom advanced
28

How do you handle dynamic tables in Selenium? Medium

Dynamic tables can be handled using XPath loops or iterating through rows and columns.

Example approach:

  • Locate table
  • Get all rows using findElements()
  • Loop through rows and validate cell values
tables dynamic
29

What is the difference between assert and verify? Easy

Assert stops execution if condition fails.

Verify logs failure but continues execution.

In TestNG, assertions are commonly used for validation.

assertions testng
30

How do you parameterize browser execution? Medium

Browser execution can be parameterized using TestNG XML or command-line arguments.

This helps run tests across multiple browsers dynamically.

cross-browser parameterization
31

What is the difference between WebDriver and RemoteWebDriver? Medium

WebDriver is used for local browser automation.

RemoteWebDriver is used when running tests on Selenium Grid or remote machines.

remotewebdriver grid
32

How do you design a scalable Selenium framework? Hard

A scalable framework includes:

  • Page Object Model
  • Reusable utilities
  • Data-driven approach
  • Proper logging
  • CI/CD integration

Framework design is often asked in senior-level interviews.

framework architecture
33

How do you handle CAPTCHA in Selenium? Hard

CAPTCHA cannot be automated directly because it is designed to block bots.

Solutions:

  • Disable CAPTCHA in test environment
  • Use test bypass mechanism
captcha limitations
34

What are common exceptions in Selenium? Easy

Common exceptions include:

  • NoSuchElementException
  • StaleElementReferenceException
  • TimeoutException
  • ElementNotInteractableException
exceptions debugging
35

How do you handle auto-suggestions in Selenium? Medium

Auto-suggestions can be handled by:

  • Typing partial text
  • Waiting for suggestion list
  • Selecting desired suggestion using loop
autosuggestion dynamic
36

Explain cross-browser testing in Selenium. Hard

Cross-browser testing ensures application works across different browsers.

It can be implemented using:

  • Selenium Grid
  • Cloud platforms like BrowserStack
  • Parameterized WebDriver setup
cross-browser testing
📊 Questions Breakdown
🟢 Easy 13
🟡 Medium 14
🔴 Hard 9
🎓 Master Selenium Training

Join our live classes with expert instructors and hands-on projects.

Enroll Now

What People Say

Testimonial

Nagmani Solanki

Digital Marketing

Edugators platform is the best place to learn live classes, and live projects by which you can understand easily and have excellent customer service.

Testimonial

Saurabh Arya

Full Stack Developer

It was a very good experience. Edugators and the instructor worked with us through the whole process to ensure we received the best training solution for our needs.

testimonial

Praveen Madhukar

Web Design

I would definitely recommend taking courses from Edugators. The instructors are very knowledgeable, receptive to questions and willing to go out of the way to help you.

Need To Train Your Corporate Team ?

Customized Corporate Training Programs and Developing Skills For Project Success.

Google AdWords Training
React Training
Angular Training
Node.js Training
AWS Training
DevOps Training
Python Training
Hadoop Training
Photoshop Training
CorelDraw Training
.NET Training

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators