Interview Prep
Interview Questions on Selenium — WebDriver, Locators, Frameworks, and What QA Interviews Actually Test
Selenium is the default automation testing tool in Indian IT companies. Every QA automation interview — from TCS to product companies — tests Selenium WebDriver, locator strategies, and framework design. Here are the questions they ask.

Selenium WebDriver is the most in-demand QA automation skill in India. Every testing interview starts here.
Selenium Interview Landscape in India
Selenium is the most widely used automation testing tool in India. TCS, Infosys, Wipro, Cognizant, and Accenture all have massive QA teams that use Selenium WebDriver for web application testing. Product companies like Flipkart, Swiggy, and Razorpay also use Selenium as part of their CI/CD pipelines.
Selenium interviews test three things: your understanding of WebDriver architecture, your ability to write locators and handle dynamic elements, and your experience with test frameworks (TestNG/JUnit + Page Object Model). Freshers get basic questions about locators and waits. Experienced candidates get framework design, parallel execution, and debugging questions.
This guide covers the actual Selenium interview questions asked in Indian companies — from WebDriver basics to advanced framework design.
Selenium interviews are 50% theory (architecture, waits, locators) and 50% practical (write code to handle this scenario). Prepare for both.
WebDriver Basics
Q1: What is Selenium? What are its components?
Selenium is an open-source suite for web browser automation. Components: 1. Selenium IDE - Browser extension for record-and-playback - No coding required, good for beginners - Limited to simple test cases 2. Selenium WebDriver - Programming API for browser automation - Supports Java, Python, C#, JavaScript - Direct browser communication (no server needed) - This is what 95% of interviews test 3. Selenium Grid - Runs tests on multiple machines/browsers in parallel - Hub-node architecture - Used for cross-browser and distributed testing 4. Selenium RC (deprecated) - Older version, replaced by WebDriver - Used a server as intermediary - Do not use — but know it exists for interview context
Q2: How does Selenium WebDriver work internally?
// WebDriver architecture (W3C WebDriver protocol):
Your Test Code (Java/Python)
↓ (HTTP requests via JSON Wire Protocol)
Browser Driver (chromedriver, geckodriver)
↓ (native browser commands)
Browser (Chrome, Firefox, Edge)
// Step by step:
// 1. Your code calls driver.findElement(By.id("login"))
// 2. WebDriver sends HTTP POST to browser driver
// 3. Browser driver translates to native browser command
// 4. Browser executes the action
// 5. Response travels back the same path
// This is why you need:
// - Selenium WebDriver library (in your project)
// - Browser driver executable (chromedriver.exe)
// - The actual browser installedQ3: What are the different types of waits in Selenium?
// 1. Implicit Wait — global, applies to all elements
driver.manage().timeouts().implicitlyWait(
Duration.ofSeconds(10)
);
// Waits up to 10s for ANY element to appear
// 2. Explicit Wait — specific condition for specific element
WebDriverWait wait = new WebDriverWait(driver,
Duration.ofSeconds(15));
WebElement element = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("result")
)
);
// Waits up to 15s for THIS element to be visible
// 3. Fluent Wait — explicit wait with polling interval
Wait<WebDriver> fluentWait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(2))
.ignoring(NoSuchElementException.class);
// 4. Thread.sleep() — NEVER use in production tests
// Hard wait, wastes time, makes tests flaky
// Best practice:
// Use Explicit Wait for specific conditions
// Avoid mixing Implicit + Explicit (unpredictable)
// Never use Thread.sleep()Locator Strategies
Q4: What are the different locator strategies? Which is fastest?
// 8 locator strategies (fastest to slowest):
1. By.id("username") // Fastest, unique
2. By.name("email") // Fast, may not be unique
3. By.className("btn-primary") // Can match multiple
4. By.tagName("input") // Too broad usually
5. By.linkText("Click Here") // Only for <a> tags
6. By.partialLinkText("Click") // Partial match for <a>
7. By.cssSelector("#login .btn") // Powerful, fast
8. By.xpath("//div[@id='main']") // Most flexible, slowest
// Priority order for choosing locators:
// 1. ID (if available and unique)
// 2. CSS Selector (fast + flexible)
// 3. XPath (when CSS cannot handle it)
// CSS Selector examples:
driver.findElement(By.cssSelector("#login")); // by ID
driver.findElement(By.cssSelector(".btn.primary")); // by class
driver.findElement(By.cssSelector("input[type='email']"));
// XPath examples:
driver.findElement(By.xpath("//input[@id='user']"));
driver.findElement(By.xpath("//div[contains(@class,'error')]"));
driver.findElement(By.xpath("//button[text()='Submit']"));Q5: How do you handle dynamic elements?
// Dynamic elements have IDs/classes that change on each load
// Example: id="btn_12345" where 12345 changes
// Solution 1: Use contains() in XPath
driver.findElement(By.xpath("//button[contains(@id,'btn_')]"));
// Solution 2: Use starts-with() in XPath
driver.findElement(By.xpath("//input[starts-with(@id,'user_')]"));
// Solution 3: Use CSS attribute selectors
driver.findElement(By.cssSelector("button[id^='btn_']")); // starts with
driver.findElement(By.cssSelector("button[id$='_submit']")); // ends with
driver.findElement(By.cssSelector("button[id*='login']")); // contains
// Solution 4: Use relative locators (Selenium 4)
driver.findElement(
RelativeLocator.with(By.tagName("input"))
.below(By.id("username_label"))
);Handling Common Scenarios
Q6: How do you handle alerts, frames, and windows?
// Alerts:
Alert alert = driver.switchTo().alert();
alert.getText(); // read alert text
alert.accept(); // click OK
alert.dismiss(); // click Cancel
alert.sendKeys("text"); // type in prompt
// Frames/iFrames:
driver.switchTo().frame("frameName"); // by name
driver.switchTo().frame(0); // by index
driver.switchTo().frame(element); // by WebElement
driver.switchTo().defaultContent(); // back to main
// Multiple Windows:
String mainWindow = driver.getWindowHandle();
Set<String> allWindows = driver.getWindowHandles();
for (String window : allWindows) {
if (!window.equals(mainWindow)) {
driver.switchTo().window(window);
// do work in new window
driver.close(); // close new window
}
}
driver.switchTo().window(mainWindow); // back to mainQ7: How do you handle dropdowns and file uploads?
// Dropdown (Select tag):
Select dropdown = new Select(
driver.findElement(By.id("country"))
);
dropdown.selectByVisibleText("India");
dropdown.selectByValue("IN");
dropdown.selectByIndex(2);
// Custom dropdown (non-Select tag):
driver.findElement(By.id("dropdown-trigger")).click();
driver.findElement(By.xpath("//li[text()='India']")).click();
// File upload:
WebElement upload = driver.findElement(By.id("file-input"));
upload.sendKeys("C:\path\to\file.pdf");
// sendKeys on file input = sets the file path
// Screenshot:
File screenshot = ((TakesScreenshot) driver)
.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(screenshot, new File("screenshot.png"));
Selenium automation is a core skill for QA engineers in India. Framework design questions separate junior from senior testers.
Test Frameworks and Design Patterns
Q8: What is the Page Object Model (POM)?
// POM = design pattern where each web page has a class
// Page class contains locators + methods for that page
// LoginPage.java
public class LoginPage {
WebDriver driver;
// Locators
By usernameField = By.id("username");
By passwordField = By.id("password");
By loginButton = By.id("login-btn");
public LoginPage(WebDriver driver) {
this.driver = driver;
}
// Page methods
public void enterUsername(String user) {
driver.findElement(usernameField).sendKeys(user);
}
public void enterPassword(String pass) {
driver.findElement(passwordField).sendKeys(pass);
}
public DashboardPage clickLogin() {
driver.findElement(loginButton).click();
return new DashboardPage(driver);
}
}
// Benefits:
// 1. Reusable — same page object used in multiple tests
// 2. Maintainable — locator changes in ONE place
// 3. Readable — tests read like business actions
// 4. Reduces code duplicationQ9: TestNG vs JUnit — which do you prefer and why?
TestNG advantages over JUnit:
- @DataProvider for data-driven testing
- Parallel test execution built-in
- Test grouping (@Test(groups = {"smoke", "regression"}))
- Dependency management (@Test(dependsOnMethods))
- testng.xml for suite configuration
- Better reporting out of the box
JUnit advantages:
- Simpler, lighter
- Better IDE integration
- Standard for unit testing
- JUnit 5 has caught up on many features
// In Indian IT companies:
// TestNG is the default for Selenium automation
// JUnit is used for unit testing Java applications
// Interview answer:
// "I prefer TestNG for Selenium because of parallel
// execution, data providers, and XML suite configuration.
// For unit testing, I use JUnit."Q10: How do you handle test data in your framework?
Common approaches: Excel files (Apache POI), JSON/YAML files, database queries, TestNG @DataProvider, properties files for configuration. The best practice is to separate test data from test logic completely. Use external files (Excel/JSON) for test data and properties files for environment configuration (URLs, credentials).
How to Prepare
Selenium Interview — Priority by Experience
0-1 Years
- • Locator strategies (all 8)
- • Waits (implicit vs explicit)
- • Alerts, frames, windows
- • Basic TestNG annotations
- • WebDriver setup
2-4 Years
- • Page Object Model
- • Data-driven testing
- • Dynamic elements
- • Selenium Grid
- • CI/CD integration
5+ Years
- • Framework architecture
- • Parallel execution
- • Custom reporting
- • Docker + Selenium Grid
- • Selenium vs Cypress/Playwright