Practice Real Company Assessment Patterns • Latest 2025–2026 Mock Tests
22 June, 2026 (Last Updated)

Top Selenium Interview Questions for Freshers

Top Selenium Interview Questions for Freshers

Key Takeaways

In this article, we will learn about:

  • Important Selenium concepts like WebDriver, locators, waits, alerts, frames, windows, and browser commands.
  • Practical Selenium automation testing interview questions for freshers.
  • Selenium Java concepts, TestNG basics, framework design, and real-time testing scenarios.
  • Common Selenium issues include dynamic elements, stale element exceptions, slow page loading, and cross-browser failures.
  • Advanced Selenium topics like Page Object Model, Selenium Grid, Maven, Jenkins, reporting, and headless testing.

Selenium remains one of the most important tools for freshers preparing for QA, automation testing, software testing, SDET, web testing, and full-stack testing roles. The global automation testing market was valued at USD 20.60 billion in 2025 and is projected to reach USD 84.22 billion by 2034, growing at a CAGR of 16.84%.

Since Selenium is widely used to automate web application testing across browsers and platforms, freshers should understand WebDriver, locators, waits, TestNG, and basic framework concepts.

This article covers practical Selenium interview questions for freshers with clear Selenium interview questions and answers to help you prepare for technical interviews.

mock test horizontal banner placement success

Selenium Basics and Core Concepts Interview Questions

Before learning advanced automation frameworks, freshers should first understand how Selenium WebDriver works, how browsers are controlled, and how web elements are located.

These Selenium interview questions for freshers cover the core concepts like WebDriver, locators, browser drivers, XPath, CSS Selectors, WebElements, and basic browser commands.

1. What is Selenium WebDriver and why is it used in automation testing?

Selenium WebDriver is a browser automation tool used to test web applications by controlling browsers like Chrome, Firefox, Edge, and Safari. It allows testers to write scripts that perform real user actions such as clicking buttons, entering text, selecting dropdowns, navigating pages, and validating results.

In automation testing, Selenium WebDriver is used to reduce manual testing effort, repeat test cases quickly, and check whether web applications work correctly across different browsers. It is commonly used for regression testing, smoke testing, functional testing, and cross-browser testing.

For example, a tester can automate a login page by entering a username, a password, clicking the login button, and verifying whether the user reaches the dashboard.

2. What are the main components of the Selenium suite?

The Selenium suite includes different tools used for web automation testing.

Selenium Component Purpose
Selenium IDE A record-and-playback tool used to create simple test scripts without much coding.
Selenium WebDriver A programming-based tool used to automate browser actions.
Selenium Grid Used to run tests on multiple browsers, machines, and operating systems in parallel.

Among these, Selenium WebDriver is the most commonly used component in real automation projects because it supports programming languages like Java, Python, C#, JavaScript, and Ruby.

Selenium IDE is useful for beginners, while Selenium Grid is useful when teams want to reduce execution time by running tests in parallel.

3. How is Selenium WebDriver different from Selenium IDE?

Selenium WebDriver and Selenium IDE are both used for web testing, but they are used in different ways.

Feature Selenium IDE Selenium WebDriver
Type Record-and-playback tool Code-based automation tool
Coding required Minimal or no coding Requires programming knowledge
Flexibility Limited Highly flexible
Best for Basic test recording Real automation projects
Language support Limited Java, Python, C#, JavaScript, Ruby
Framework support Limited Supports TestNG, JUnit, Maven, etc.

Selenium IDE is useful for quick test recording, but Selenium WebDriver is preferred in professional automation testing because it supports reusable scripts, framework design, test data handling, reporting, and integration with tools like Maven and Jenkins.

4. What is the role of a browser driver in Selenium?

A browser driver acts as a bridge between Selenium WebDriver and the browser. Selenium test scripts do not directly control the browser. Instead, WebDriver sends commands to the browser driver, and the browser driver communicates with the actual browser.

For example:

  • Chrome uses ChromeDriver
  • Firefox uses GeckoDriver
  • Edge uses EdgeDriver
  • Safari uses SafariDriver

When a Selenium script says click() or sendKeys(), the browser driver converts that command into browser-specific actions.

Example:

WebDriver driver = new ChromeDriver();

driver.get(“https://example.com”);

Here, ChromeDriver helps Selenium launch and control the Chrome browser.

5. How does Selenium WebDriver interact with a browser?

Selenium WebDriver interacts with a browser by sending automation commands to the browser driver. The browser driver then communicates with the browser and performs the required action.

The flow is:

Test Script → Selenium WebDriver → Browser Driver → Browser

For example, when a script contains:

driver.findElement(By.id(“email”)).sendKeys(“[email protected]”);

Selenium finds the element with the ID email and enters the text into that field.

WebDriver can perform actions like:

  • Opening a browser
  • Navigating to a URL
  • Clicking buttons
  • Typing text
  • Reading page text
  • Handling alerts, windows, and frames
  • Closing the browser

This is how Selenium simulates real user actions on a web application.

6. What are locators in Selenium, and why are they important?

Locators are used to identify web elements on a webpage. Selenium needs locators to find elements before performing actions like click, type, select, or verify.

For example, to enter text into a username field, Selenium must first locate that field.

driver.findElement(By.id(“username”)).sendKeys(“admin”);

Here, id(“username”) is the locator.

Locators are important because automation scripts depend on them to interact with the correct elements. If locators are weak or unstable, test scripts may fail when the webpage changes.

Good locators should be:

  • Unique
  • Stable
  • Easy to read
  • Less dependent on page layout
  • Suitable for dynamic web pages

Strong locator strategy is one of the most important skills in Selenium automation.

7. What are the different types of locators used in Selenium?

Selenium provides different locator strategies to identify web elements.

Locator Type Example
ID By.id(“username”)
Name By.name(“email”)
Class Name By.className(“btn-login”)
Tag Name By.tagName(“input”)
Link Text By.linkText(“Login”)
Partial Link Text By.partialLinkText(“Log”)
XPath By.xpath(“//input[@id=’username’]”)
CSS Selector By.cssSelector(“input#username”)

ID is usually preferred when it is unique and stable. CSS Selector and XPath are useful when elements do not have simple IDs or names.

In real projects, testers often use a mix of ID, CSS Selector, and XPath depending on the webpage structure.

8. What is the difference between findElement() and findElements()?

findElement() and findElements() are used to locate elements in Selenium, but they behave differently.

Feature findElement() findElements()
Return type Single WebElement List of WebElements
Used for Finding one element Finding multiple matching elements
If element is not found Throws NoSuchElementException Returns an empty list
Example use case Login button All links on a page

Example of findElement():

WebElement loginButton = driver.findElement(By.id(“login”));

Example of findElements():

List<WebElement> links = driver.findElements(By.tagName(“a”));

Use findElement() when only one element is expected. Use findElements() when multiple elements may match the locator.

9. What happens when Selenium cannot find an element?

When Selenium cannot find an element using findElement(), it throws a NoSuchElementException. This means Selenium searched for the element on the page but could not locate it with the given locator.

Common reasons include:

  • Wrong locator
  • Element not loaded yet
  • Element inside an iframe
  • Element is hidden
  • Page changed after script was written
  • Dynamic ID or class value
  • Timing issue due to slow page load

Example:

driver.findElement(By.id(“submitButton”)).click();

If no element with ID submitButton exists, Selenium throws an exception.

To handle this, testers can use better locators, explicit waits, iframe switching, or check whether the element is present before interacting with it.

10. What is XPath in Selenium?

XPath is a locator strategy used to find elements in an HTML document using the page’s DOM structure. It is useful when elements do not have unique IDs, names, or simple attributes.

Example:

driver.findElement(By.xpath(“//input[@id=’email’]”)).sendKeys(“[email protected]”);

Here, XPath finds an input element whose id is email.

XPath can locate elements using:

  • Tag name
  • Attribute value
  • Text
  • Parent-child relationship
  • Sibling relationship
  • Partial attribute match

Example using text:

driver.findElement(By.xpath(“//button[text()=’Login’]”)).click();

XPath is powerful because it can handle complex and dynamic web pages, but poorly written XPath can become slow and difficult to maintain.

11. What is the difference between absolute XPath and relative XPath?

Absolute XPath starts from the root of the HTML document and follows the complete path to the element. Relative XPath starts from anywhere in the DOM and directly targets the required element.

Feature Absolute XPath Relative XPath
Starts from Root node /html Anywhere in the DOM
Begins with Single slash / Double slash //
Stability Less stable More stable
Readability Long and difficult Short and readable
Recommended? Usually no Yes

Absolute XPath example:

/html/body/div[1]/form/input[1]

Relative XPath example:

//input[@id=’email’]

Relative XPath is preferred because it is shorter, easier to maintain, and less likely to break when page layout changes.

12. What is CSS Selector in Selenium?

CSS Selector is a locator strategy used to find web elements based on CSS-style patterns. It is commonly used because it is fast, readable, and works well with attributes like ID, class, and tag name.

Examples:

driver.findElement(By.cssSelector(“#email”));

This selects an element with ID email.

driver.findElement(By.cssSelector(“.login-btn”));

This selects an element with class login-btn.

driver.findElement(By.cssSelector(“input[name=’username’]”));

This selects an input element with the name username.

CSS Selectors are useful for locating elements using:

  • ID
  • Class
  • Attribute
  • Parent-child relationship
  • Partial attribute values

They are widely used in Selenium because they are clean and efficient for most web automation needs.

13. XPath vs CSS Selector: which one is preferred and why?

Both XPath and CSS Selector are useful in Selenium, but CSS Selector is often preferred for simple and stable locators because it is usually faster, cleaner, and easier to read.

Feature XPath CSS Selector
Syntax Can be complex Usually cleaner
Speed Slightly slower in some cases Usually faster
Text matching Supports text-based search Does not directly support text matching
DOM traversal Can move forward and backward Mostly moves forward
Best use Complex relationships and text matching ID, class, attributes, simple hierarchy

CSS Selector example:

input#email

XPath example:

//input[@id=’email’]

In interviews, a good answer is: use ID first if stable, CSS Selector for simple attribute-based locators, and XPath when you need text matching or complex DOM navigation.

14. What are WebElements in Selenium?

A WebElement in Selenium represents an HTML element on a webpage. Once Selenium finds an element using a locator, it stores it as a WebElement and performs actions on it.

Examples of WebElements include:

  • Text boxes
  • Buttons
  • Links
  • Dropdowns
  • Checkboxes
  • Radio buttons
  • Tables
  • Images

Example:

WebElement emailField = driver.findElement(By.id(“email”));

emailField.sendKeys(“[email protected]”);

Here, emailField is a WebElement representing the email input field.

Common WebElement methods include:

  • click()
  • sendKeys()
  • getText()
  • clear()
  • isDisplayed()
  • isEnabled()
  • isSelected()

WebElements are the objects Selenium interacts with during test automation.

15. What are common Selenium WebDriver commands?

Selenium WebDriver provides many commands to control the browser and interact with web elements.

Command Purpose
get() Opens a URL
findElement() Finds a single element
findElements() Finds multiple elements
click() Clicks an element
sendKeys() Enters text
clear() Clears text from a field
getText() Gets visible text
getTitle() Gets page title
getCurrentUrl() Gets current page URL
close() Closes current browser window
quit() Closes all browser windows

Example:

driver.get(“https://example.com”);
driver.findElement(By.id(“username”)).sendKeys(“admin”);
driver.findElement(By.id(“login”)).click();

These commands are the foundation of Selenium automation scripts.

Intermediate Selenium Interview Questions

Here are the intermediate-level Selenium interview questions that test practical automation knowledge.

These questions focus on handling dynamic elements, waits, frames, windows, dropdowns, screenshots, Excel data, TestNG, cross-browser testing, and real-time automation challenges.

1. Explain how you would handle dynamic elements in Selenium.

Dynamic elements are web elements whose attributes change when the page reloads or when user actions happen. For example, an element ID may change from user_123 to user_456.

To handle dynamic elements, use stable locator strategies instead of depending on full dynamic values.

Common approaches:

  • Use XPath functions like contains(), starts-with(), or text().
  • Use CSS Selectors with stable attributes.
  • Avoid absolute XPath.
  • Use explicit waits until the element is visible or clickable.
  • Locate the element using nearby stable parent-child relationships.

Example:

driver.findElement(By.xpath(“//button[contains(text(),’Login’)]”)).click();

Dynamic elements are common in modern web apps, so strong locator writing is very important in Selenium automation.

2. How are dropdowns handled in Selenium?

Dropdown handling depends on whether the dropdown is created using the HTML <select> tag or custom HTML.

For standard <select> dropdowns, Selenium provides the Select class.

Example:

WebElement country = driver.findElement(By.id(“country”));

Select select = new Select(country);

 

select.selectByVisibleText(“India”);

select.selectByValue(“IN”);

select.selectByIndex(2);

For custom dropdowns that are built using div, span, or li tags, the Select class will not work. In that case, click the dropdown first and then click the required option using XPath or CSS Selector.

Example:

driver.findElement(By.id(“cityDropdown”)).click();

driver.findElement(By.xpath(“//li[text()=’Chennai’]”)).click();

So, first inspect the HTML structure, then choose the correct approach.

3. How do you handle checkboxes and radio buttons?

Checkboxes and radio buttons are handled using WebElement methods like click(), isSelected(), isDisplayed(), and isEnabled().

Before clicking, it is good to check whether the element is already selected.

Example for checkbox:

WebElement checkbox = driver.findElement(By.id(“terms”));

if (!checkbox.isSelected()) {

checkbox.click();

}

Example for radio button:

WebElement gender = driver.findElement(By.id(“male”));

gender.click();

Checkboxes allow multiple selections, while radio buttons usually allow only one option from a group. In automation, validation is important because clicking an already selected checkbox can unselect it.

4. Alerts, windows, and frames are handled differently in Selenium. Explain.

Alerts, windows, and frames are different browser or page contexts, so Selenium handles each one differently.

Feature Alert Window/Tab Frame/iFrame
Meaning Browser popup Separate browser tab/window Page embedded inside another page
Selenium method switchTo().alert() switchTo().window() switchTo().frame()
Example action Accept/dismiss alert Move to new tab Access elements inside iframe
Common issue NoAlertPresentException Wrong window focus Element not found until frame is switched

Alert example:

driver.switchTo().alert().accept();

Window example:

driver.switchTo().window(windowId);

Frame example:

driver.switchTo().frame(“frameName”);

Selenium can interact only with the currently active context, so switching is necessary.

5. Explain waits in Selenium with their practical use.

Waits in Selenium are used to handle timing issues between the test script and the web application. Sometimes, Selenium executes commands faster than the page loads, causing failures.

The three commonly used waits are:

Wait Type Meaning Best Used For
Implicit Wait Waits globally for elements to appear Basic element loading
Explicit Wait Waits for a specific condition Clickable, visible, alert present
Fluent Wait Waits with polling and ignored exceptions Dynamic or unstable elements

Explicit wait example:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement loginBtn = wait.until(

ExpectedConditions.elementToBeClickable(By.id(“login”))
);

loginBtn.click();

Explicit wait is usually preferred because it gives better control over specific conditions.

6. Why should Thread.sleep() be avoided in Selenium automation?

Thread.sleep() pauses the script for a fixed time, whether the element is ready or not. This makes automation slow and unreliable.

Example:

Thread.sleep(5000);

This pauses execution for 5 seconds every time. If the element loads in 1 second, 4 seconds are wasted. If the element takes 8 seconds, the test still fails.

Instead of Thread.sleep(), use explicit waits.

Better approach:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(“username”)));

Explicit waits wait only until the required condition is met. This makes Selenium scripts faster, stable, and suitable for real automation frameworks.

7. What is synchronization in Selenium?

Synchronization means matching the speed of the automation script with the speed of the web application. Selenium may try to interact with an element before it becomes visible, clickable, or loaded, which causes failures.

Synchronization is needed when:

Page loads slowly

  • AJAX calls update data
  • Elements appear after a delay
  • Buttons become clickable after validation
  • Frames or popups load dynamically

Selenium handles synchronization using waits.

Example:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

wait.until(ExpectedConditions.elementToBeClickable(By.id(“submit”))).click();

Without synchronization, tests may fail randomly even if the application works correctly. Proper waits improve test stability and reduce flaky test failures.

8. How do you handle a StaleElementReferenceException?

StaleElementReferenceException occurs when Selenium finds an element, but the page updates before Selenium interacts with it. The old element reference becomes invalid because the DOM has changed.

Common causes include:

  • Page refresh
  • AJAX update
  • Element reload
  • DOM change after click
  • Dynamic table or list update

Wrong approach:

WebElement button = driver.findElement(By.id(“save”));

driver.navigate().refresh();

button.click();

Here, the old button reference becomes stale.

Correct approach:

driver.navigate().refresh();

 

WebElement button = driver.findElement(By.id(“save”));

button.click();

You can also use explicit wait and re-locate the element before performing the action. The main fix is to avoid storing elements too early when the page is likely to change.

9. A visible element is not clickable. How would you fix it?

An element may be visible but still not clickable due to overlays, loading screens, disabled state, wrong locator, scrolling issue, or another element covering it.

To fix this, check:

  • Is the element actually enabled?
  • Is another popup or loader covering it?
  • Is the element inside a frame?
  • Does it need scrolling into view?
  • Is the locator pointing to the correct element?
  • Is the page still loading?

Use explicit wait:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

 

WebElement button = wait.until(

ExpectedConditions.elementToBeClickable(By.id(“submit”))

);

 

button.click();

If needed, scroll to the element using JavaScript or close the overlay first. JavaScript click should be used only when normal Selenium click is not suitable.

10. How do you perform mouse hover and drag-and-drop actions?

Selenium provides the Actions class to perform advanced user interactions like mouse hover, drag and drop, right-click, double-click, and keyboard actions.

Mouse hover example:

Actions actions = new Actions(driver);

 

WebElement menu = driver.findElement(By.id(“products”));

actions.moveToElement(menu).perform();

Drag and drop example:

WebElement source = driver.findElement(By.id(“source”));

WebElement target = driver.findElement(By.id(“target”));

 

actions.dragAndDrop(source, target).perform();

The Actions class is useful when normal click() or sendKeys() is not enough. It is commonly used for menus, sliders, drag-and-drop widgets, and hover-based navigation.

11. Explain file upload and screenshot handling in Selenium.

For file upload, Selenium can use sendKeys() when the file input field has type=”file”.

File upload example:

WebElement upload = driver.findElement(By.id(“resume”));

upload.sendKeys(“C:\\Users\\Admin\\Documents\\resume.pdf”);

This works only when Selenium can access the actual file input element.

For screenshots, Selenium uses the TakesScreenshot interface.

Screenshot example:

TakesScreenshot ts = (TakesScreenshot) driver;

File source = ts.getScreenshotAs(OutputType.FILE);
File target = new File(“screenshot.png”);

FileUtils.copyFile(source, target);

Screenshots are useful for debugging failed test cases, reporting issues, and attaching evidence in automation reports.

12. How do you read test data from Excel in Selenium automation?

Selenium itself does not read Excel files. In Java-based Selenium frameworks, libraries like Apache POI are commonly used to read data from Excel.

The usual flow is:

  1. Store test data in an Excel sheet.
  2. Use Apache POI to read rows and columns.
  3. Pass the data into Selenium test scripts.
  4. Run the same test with different input values.

Example use case:

A login test can run with multiple usernames and passwords from Excel.

Username Password

[email protected] admin123

[email protected] user123

This approach is useful for data-driven testing, where the same test case is executed with multiple data sets. It improves coverage and avoids hardcoding test data in scripts.

13. How do you run Selenium tests in different browsers?

To run Selenium tests in different browsers, create WebDriver objects based on the browser requirement.

Chrome example:

WebDriver driver = new ChromeDriver();

Firefox example:

WebDriver driver = new FirefoxDriver();

Edge example:

WebDriver driver = new EdgeDriver();

In real frameworks, the browser name is usually passed from a configuration file, TestNG XML file, Maven command, or CI/CD pipeline.

Example logic:

if (browser.equals(“chrome”)) {

driver = new ChromeDriver();

} else if (browser.equals(“firefox”)) {

driver = new FirefoxDriver();

}

This helps perform cross-browser testing and verify whether the web application works consistently across different browsers.

14. How do you validate page title, URL, and text using Selenium?

Selenium provides methods to capture the page title, current URL, and visible text from elements. These values can be validated using assertions.

Page title:

String title = driver.getTitle();

Assert.assertEquals(title, “Dashboard”);

Current URL:

String url = driver.getCurrentUrl();

Assert.assertTrue(url.contains(“dashboard”));

Element text:

String message = driver.findElement(By.id(“success”)).getText();

Assert.assertEquals(message, “Login successful”);

These validations are important because automation is not only about performing actions. A test case should also verify whether the expected result is displayed after the action.

15. What is the role of TestNG in Selenium automation?

TestNG is a testing framework used with Selenium to organize, execute, and manage test cases properly. Selenium automates browser actions, while TestNG helps structure the tests.

Feature Selenium WebDriver TestNG
Purpose Automates browser actions Manages test execution
Used for Click, type, navigate, validate UI Annotations, assertions, grouping, reports
Example driver.findElement().click() @Test, @BeforeMethod, Assert
Role in framework Browser automation layer Test management layer

TestNG is useful for:

  • Running test cases
  • Using annotations like @Test, @BeforeMethod, @AfterMethod
  • Performing assertions
  • Grouping tests
  • Running tests in parallel
  • Generating basic reports
  • Managing test execution through XML files

In real projects, Selenium and TestNG are often used together to build maintainable automation frameworks.

Advanced Selenium Interview Questions

Here are advanced Selenium interview questions that test framework-level understanding, execution strategy, maintainability, CI/CD integration, parallel testing, reporting, and real-time automation challenges.

These questions are useful for freshers who already know Selenium basics and want to prepare for stronger technical discussions.

1. Explain the Page Object Model in Selenium.

Page Object Model, or POM, is a design pattern used in Selenium automation to keep page elements and test logic separate. In POM, each web page is represented as a separate Java class, and the elements and actions of that page are written inside that class.

For example, a login page can have a LoginPage class containing username field, password field, login button, and login method.

public class LoginPage {

WebDriver driver;

By username = By.id(“username”);

By password = By.id(“password”);

By loginBtn = By.id(“login”);

public LoginPage(WebDriver driver) {

this.driver = driver;

}

public void login(String user, String pass) {

driver.findElement(username).sendKeys(user);

driver.findElement(password).sendKeys(pass);

driver.findElement(loginBtn).click();

}

}

POM improves code reusability, readability, and maintenance. If a locator changes, we update it only in one page class instead of changing it in multiple test cases.

2. Why is Page Object Model preferred in Selenium frameworks?

Page Object Model is preferred because it makes Selenium automation more maintainable and scalable. In real projects, a single page may be used in many test cases. If locators are directly written inside every test case, even a small UI change can break many scripts.

With POM, locators and page actions are stored in one place.

Benefits of POM:

  • Separates test logic from page logic.
  • Reduces duplicate code.
  • Makes scripts easier to maintain.
  • Improves readability.
  • Supports reusable page methods.
  • Helps build a proper automation framework.

For example, the login method can be reused in smoke tests, regression tests, and end-to-end test cases. This is why POM is commonly asked in advanced Selenium interviews.

3. What is the difference between Page Object Model and Page Factory?

Page Object Model is a design pattern, while Page Factory is a Selenium feature used to initialize web elements using annotations like @FindBy.

Feature Page Object Model Page Factory
Meaning Design pattern for organizing page classes Selenium support class for initializing elements
Locator style Uses By locators Uses @FindBy annotation
Initialization Elements located manually Elements initialized using PageFactory.initElements()
Maintenance Easy to maintain Cleaner syntax, but must be used carefully
Usage Common in frameworks Optional enhancement to POM

Page Factory example:

@FindBy(id = “username”)

WebElement username;

 

@FindBy(id = “password”)

WebElement password;

POM can be used with or without Page Factory. Many teams prefer simple By locators because they are easier to re-locate and handle in dynamic applications.

4. How would you design a basic Selenium automation framework?

A basic Selenium framework should be designed to keep test scripts clean, reusable, and easy to maintain. It should separate browser setup, page classes, test data, utilities, reports, and test cases.

A common framework structure includes:

src/test/java
├── base
├── pages
├── tests
├── utilities
├── listeners
└── testdata

Important components:

  • Base class: Browser setup and teardown.
  • Page classes: Locators and page actions.
  • Test classes: Actual test scenarios.
  • Utility classes: Screenshots, waits, Excel reading, config reading.
  • Test data: Excel, JSON, or properties files.
  • Reports: Extent Reports or Allure Reports.
  • TestNG XML: Test suite execution.

A good framework should support reusability, cross-browser testing, parallel execution, reporting, and easy debugging.

5. What is a data-driven framework in Selenium?

A data-driven framework is an automation framework where test data is separated from test scripts. The same test case can run multiple times with different input values.

For example, a login test can run with multiple usernames and passwords from Excel, CSV, JSON, or a database.

Username Password

[email protected] valid123

[email protected] wrong123

[email protected]

The test script remains the same, but the input data changes.

Advantages:

  • Reduces duplicate test cases.
  • Improves test coverage.
  • Makes data maintenance easier.
  • Useful for login, registration, search, payment, and form validation tests.

In Selenium Java frameworks, Apache POI is commonly used to read Excel data, and TestNG @DataProvider is often used to pass multiple data sets to test methods.

6. What is the difference between data-driven, keyword-driven, and hybrid frameworks?

These are common Selenium framework types used in automation projects.

Framework Type Meaning Best Used For
Data-driven framework Test data is separated from test scripts Running same test with multiple data sets
Keyword-driven framework Test actions are written as keywords Allowing non-coders to understand test flow
Hybrid framework Combination of data-driven, keyword-driven, POM, utilities, and reporting Real-time automation projects

Example:

In a data-driven framework, login test data comes from Excel.

In a keyword-driven framework, actions may be written like openBrowser, enterText, clickButton.

In a hybrid framework, page classes, test data, utilities, reports, and reusable methods are combined.

Most real Selenium frameworks are hybrid because they need flexibility, maintainability, and scalability.

7. How does parallel execution work in Selenium?

Parallel execution means running multiple test cases at the same time instead of running them one by one. It helps reduce total execution time, especially when the test suite has many test cases.

In Selenium with TestNG, parallel execution can be configured in the testng.xml file.

<suite name=”Suite” parallel=”tests” thread-count=”3″>

Parallel execution can happen at different levels:

  • Methods
  • Classes
  • Tests
  • Browsers

For safe parallel execution, each test thread should have its own WebDriver instance. This is often handled using ThreadLocal<WebDriver>.

If WebDriver is shared between tests, one test may affect another, causing random failures. That is why proper driver management is important in parallel testing.

8. What is Selenium Grid and why is it used?

Selenium Grid is used to run Selenium tests on multiple browsers, operating systems, and machines at the same time. It is useful for cross-browser testing and parallel execution.

For example, the same test can run on:

  • Chrome on Windows
  • Firefox on Linux
  • Edge on Windows
  • Safari on macOS

Selenium Grid follows a hub-node or distributed execution concept. In Selenium Grid 4, the architecture is more flexible and supports distributed test execution.

Benefits of Selenium Grid:

  • Reduces test execution time.
  • Supports cross-browser testing.
  • Allows remote browser execution.
  • Helps test on different environments.
  • Useful for CI/CD pipelines.

In real projects, Selenium Grid is often used with Jenkins, Docker, cloud testing platforms, or remote browser environments.

9. How do you integrate Selenium with Maven?

Maven is used in Selenium projects to manage dependencies, build the project, and run tests from the command line or CI/CD tools.

In a Selenium Maven project, dependencies like Selenium, TestNG, WebDriverManager, Apache POI, and Extent Reports are added in the pom.xml file.

Example dependency:

<dependency>

<groupId>org.seleniumhq.selenium</groupId>

<artifactId>selenium-java</artifactId>

<version>4.x.x</version>

</dependency>

Maven helps by:

  • Managing library versions.
  • Downloading dependencies automatically.
  • Running tests using commands.
  • Supporting CI/CD integration.
  • Maintaining a standard project structure.

Common Maven command:

mvn test

This makes Selenium test execution easier and more professional in real automation projects.

10. How do you integrate Selenium tests with Jenkins?

Jenkins is used to run Selenium test cases automatically as part of a CI/CD pipeline. It helps teams execute automation tests after code changes, scheduled builds, or deployment.

The basic Jenkins integration flow is:

  1. Push Selenium framework code to GitHub or GitLab.
  2. Create a Jenkins job.
  3. Connect Jenkins with the repository.
  4. Configure Maven command like mvn test.
  5. Run tests automatically.
  6. Publish reports after execution.

Common Jenkins use cases:

  • Run regression tests daily.
  • Run smoke tests after deployment.
  • Trigger tests after code commits.
  • Generate and email test reports.
  • Execute tests on remote machines or Selenium Grid.

In interviews, mention that Jenkins does not replace Selenium. Selenium automates the browser, while Jenkins schedules and executes the automation suite.

11. What is headless browser testing in Selenium?

Headless browser testing means running browser automation without opening the visible browser UI. The test still runs in a real browser engine, but the browser window is not displayed.

Example in Chrome:

ChromeOptions options = new ChromeOptions();

options.addArguments(“–headless=new”);

 

WebDriver driver = new ChromeDriver(options);

Headless testing is useful when tests are executed on servers, Docker containers, or CI/CD pipelines where a visible browser is not required.

Advantages:

  • Faster execution in many cases.
  • Useful for Jenkins or cloud environments.
  • Saves system resources.
  • Suitable for smoke and regression tests.

However, some UI-related issues may behave differently in headless mode. So, important visual flows should also be tested in normal browser mode when needed.

12. How do you execute JavaScript in Selenium WebDriver?

Selenium WebDriver provides JavascriptExecutor to execute JavaScript commands directly in the browser. It is useful when normal Selenium actions are not enough.

Example:

JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(“window.scrollBy(0,500)”);

Common uses of JavaScriptExecutor:

  • Scroll to an element.
  • Click an element when normal click fails.
  • Get page title or URL.
  • Highlight elements for debugging.
  • Handle hidden elements carefully.
  • Scroll to bottom of page.

Click example:

WebElement button = driver.findElement(By.id(“submit”));

js.executeScript(“arguments[0].click();”, button);

JavaScriptExecutor should be used carefully. A normal Selenium action is preferred because it behaves closer to real user interaction.

13. How do you handle CAPTCHA and OTP in Selenium automation?

CAPTCHA and OTP should not be directly automated in normal Selenium test cases because they are designed to prevent automated access.

For CAPTCHA, the correct approach is to:

  • Disable CAPTCHA in the test environment.
  • Use a test bypass flag.
  • Ask developers to provide a test mode.
  • Validate CAPTCHA only manually or through separate security testing.

For OTP-based login, use controlled test approaches such as:

  • Fixed OTP in lower environments.
  • OTP retrieval from test database.
  • Mock OTP service.
  • Test API to fetch OTP.
  • Email/SMS test inbox integration.

In interviews, avoid saying Selenium can easily automate CAPTCHA. A better answer is that automation should use test-friendly alternatives while keeping CAPTCHA active in production.

14. How do you generate reports in Selenium automation?

Selenium does not provide advanced reporting by itself. Reporting is usually added using tools like TestNG reports, Extent Reports, Allure Reports, or custom reporting utilities.

A good automation report should include:

  • Test case name
  • Pass/fail status
  • Error message
  • Execution time
  • Browser name
  • Screenshot on failure
  • Logs or steps executed

In TestNG, basic reports are generated automatically after execution. For better visual reports, Extent Reports or Allure Reports are commonly used.

Example use case:

When a test fails, the framework captures a screenshot and attaches it to the report. This helps testers and developers quickly understand why the failure happened.

Reports are important for debugging, client updates, CI/CD results, and regression test tracking.

15. How do you improve the stability of Selenium test scripts?

Selenium test stability means reducing flaky failures and making scripts reliable across runs. A test should fail only when there is a real application issue, not because of poor synchronization or weak locators.

Ways to improve stability:

  • Use explicit waits instead of Thread.sleep().
  • Write stable locators.
  • Avoid absolute XPath.
  • Re-locate elements after DOM updates.
  • Handle frames, windows, and alerts properly.
  • Use Page Object Model.
  • Keep test data separate.
  • Capture screenshots on failures.
  • Avoid test dependency where possible.
  • Run tests on stable test environments.
  • Use retry only for known flaky external issues.

A stable Selenium framework should be maintainable, readable, reusable, and easy to debug. This is what interviewers usually expect from an advanced Selenium answer.

Conceptual and Scenario-based Selenium Interview Questions

Here are scenario-based Selenium interview questions that test how well you can apply Selenium concepts in real automation situations.

These questions help freshers explain debugging, waits, locators, frames, windows, browser issues, and test stability practically.

1. A button is visible on the page, but Selenium says it is not clickable. How would you handle it?

This usually happens when the button is visible but not ready for interaction. The element may be covered by a loader, popup, sticky header, or another invisible element. It can also happen if the button is disabled, outside the visible screen area, or inside an iframe.

I would first check whether the locator is correct and whether the element is enabled. Then I would use an explicit wait until the element becomes clickable.

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));

WebElement button = wait.until(

ExpectedConditions.elementToBeClickable(By.id(“submit”))

);

button.click();

If the element is below the screen, I would scroll to it. If an overlay is blocking it, I would wait for the overlay to disappear before clicking.

2. A test passes sometimes and fails sometimes. What could be the reason?

If a test passes sometimes and fails sometimes, it is called a flaky test. This usually happens because of timing issues, unstable locators, slow page loading, dynamic elements, test data issues, browser compatibility problems, or dependency on another test case.

I would check:

  • Whether proper waits are used
  • Whether the locator is stable
  • Whether the element loads through AJAX
  • Whether test data changes between runs
  • Whether the test depends on another test
  • Whether the environment is stable

For example, if a script clicks a button before it becomes clickable, the test may pass on fast runs and fail on slow runs. The best fix is to use explicit waits, stable locators, independent test data, and proper test setup.

3. A web element ID changes every time the page reloads. How would you locate it?

If an element ID changes on every reload, I would avoid using the full dynamic ID. Instead, I would use stable attributes, partial matching, text, CSS Selector, or XPath functions like contains() and starts-with().

For example, if the ID changes like user_123, user_456, and user_789, but always starts with user_, I can use:

driver.findElement(By.xpath(“//input[starts-with(@id,’user_’)]”));

Or:

driver.findElement(By.cssSelector(“input[id^=’user_’]”));

I would also inspect nearby stable elements and use parent-child relationships if needed. The goal is to create a locator that remains valid even when dynamic values change.

4. A page takes time to load, and your test fails. What would you do?

If a page takes time to load and the test fails, I would avoid using Thread.sleep() as a permanent solution. Instead, I would use explicit waits to wait for a specific condition, such as element visibility, clickability, or page title.

For example:

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));

wait.until(

ExpectedConditions.visibilityOfElementLocated(By.id(“dashboard”))

);

I would also check whether the page uses AJAX calls, lazy loading, or delayed rendering. If yes, I would wait for the exact element needed for the next action instead of waiting blindly. This makes the script faster and more stable.

5. A dropdown is not created using the HTML select tag. How would you handle it?

If a dropdown is not built using the HTML select tag, Selenium’s Select class will not work. Many modern websites use custom dropdowns made with div, span, ul, or li tags.

In this case, I would handle it like a normal web element. First, I would click the dropdown, then locate and click the required option.

driver.findElement(By.id(“cityDropdown”)).click();

driver.findElement(By.xpath(“//li[text()=’Chennai’]”)).click();

Before selecting the option, I may use an explicit wait to ensure the dropdown options are visible. The key point is to inspect the HTML first and choose the handling method based on the element structure.

6. A login test works in Chrome but fails in Firefox. How would you debug it?

If a login test works in Chrome but fails in Firefox, I would first identify whether the failure is due to browser behavior, locator issue, timing issue, or driver compatibility.

I would check:

  • Whether FirefoxDriver/GeckoDriver is correctly configured
  • Whether the same element locator works in Firefox
  • Whether the page loads differently in Firefox
  • Whether browser-specific popups appear
  • Whether waits are properly used
  • Whether the application has browser compatibility issues

I would run the test in Firefox with screenshots and logs enabled. If the element is loading slower in Firefox, I would add explicit waits. If the UI behaves differently, I would adjust the locator or report it as a browser compatibility issue.

7. A Selenium script fails due to a stale element reference exception. What does it mean, and how would you fix it?

A stale element reference exception means Selenium found an element earlier, but that element is no longer attached to the current DOM. This usually happens when the page refreshes, an AJAX call updates the section, or the element is re-rendered.

For example, this can fail:

WebElement button = driver.findElement(By.id(“save”));

driver.navigate().refresh();

button.click();

The old button reference becomes invalid after refresh.

To fix it, I would locate the element again after the DOM update:

driver.navigate().refresh();

WebElement button = driver.findElement(By.id(“save”));

button.click();

I can also use explicit waits and avoid storing WebElements too early when the page is dynamic.

8. A test case requires switching to a new tab and validating content. How would you do it?

To handle a new tab, I would store the current window handle first, perform the action that opens the new tab, then switch to the new window handle.

String parentWindow = driver.getWindowHandle();

driver.findElement(By.id(“openTab”)).click();

Set<String> allWindows = driver.getWindowHandles();

for (String window : allWindows) {

if (!window.equals(parentWindow)) {

driver.switchTo().window(window);

break;

}

}

After switching, I would validate the title, URL, or page content.

Assert.assertTrue(driver.getTitle().contains(“Details”));

After validation, I can close the new tab and switch back to the parent window.

driver.close();

driver.switchTo().window(parentWindow);

9. A website has multiple iframes. How would you switch to the correct frame?

If a website has multiple iframes, Selenium cannot directly interact with elements inside them. I must first switch to the correct frame.

I would inspect the page and identify the frame using its name, ID, index, or WebElement.

driver.switchTo().frame(“paymentFrame”);

Or:

WebElement frame = driver.findElement(By.xpath(“//iframe[@title=’Payment’]”));

driver.switchTo().frame(frame);

After switching, I can interact with elements inside the iframe.

driver.findElement(By.id(“cardNumber”)).sendKeys(“4111111111111111”);

Once done, I would switch back to the main page:

driver.switchTo().defaultContent();

For multiple nested frames, I would switch step by step from parent frame to child frame.

10. A file upload button is available on the page. How would you automate it?

If the file upload field uses an HTML input tag with type=”file”, I would automate it using sendKeys() by passing the file path.

WebElement upload = driver.findElement(By.id(“resume”));

upload.sendKeys(“C:\\Users\\Admin\\Documents\\resume.pdf”);

This is the simplest and most reliable method because Selenium directly sends the file path to the input element.

However, if the upload button opens a native Windows file dialog, Selenium cannot directly control that dialog because it works only with browsers. In such cases, I would try to locate the hidden file input element. If that is not possible, tools like Robot Class or AutoIT may be used, but the preferred approach is always to interact with the actual file input field.

Best Ways to Prepare for Selenium Interviews

Preparing for Selenium interviews becomes easier when you build your basics first and then move into hands-on automation practice.

Most Selenium interview questions for freshers test your understanding of manual testing, WebDriver, locators, waits, Java basics, and simple framework design.

  • Learn Manual Testing Basics First: Understand test cases, test scenarios, bug reports, SDLC, STLC, functional testing, regression testing, smoke testing, and sanity testing. These basics help you answer Selenium testing interview questions more confidently.
  • Understand Selenium WebDriver Concepts: Revise browser drivers, WebElements, locators, waits, alerts, windows, frames, dropdowns, screenshots, and browser commands. These are the core areas asked in most Selenium technical rounds.
  • Practise Locator Writing Regularly: Work with XPath, CSS Selector, ID, name, class name, link text, and partial link text using real websites. Strong locator writing helps you handle dynamic elements and real-time web pages better.
  • Build Small Selenium Projects: Create simple projects like login automation, form validation, e-commerce product search, web table handling, and file upload automation. Projects help you explain practical answers instead of only memorising theory.
  • Learn Selenium with Java and Framework Basics: Practise Java basics, OOP concepts, exception handling, collections, methods, classes, Maven, TestNG, Page Object Model, utility classes, config files, reports, logs, and reusable methods. This is especially useful for Selenium Java interview questions.
  • Practise MCQs, Mock Tests, and Interview Questions: Solve Selenium interview questions and answers, automation testing MCQs, Java-based Selenium questions, and scenario-based questions. Use PlacementPreparation.io to practise Selenium MCQs, mock tests, and interview-based exercises for placement and technical rounds.
  • Learn with GUVI Courses and Zen Class: Use GUVI courses to learn automation testing, Java, web development, software testing, and full-stack concepts in a structured way. You can also choose GUVI Zen Class for mentor-led learning, hands-on projects, coding practice, placement guidance, and career support.

Final Words

Selenium is an important skill for freshers preparing for QA, automation testing, SDET, and software testing roles.

Since many companies use automation to test web applications faster and more accurately, learning Selenium can improve your interview readiness.


FAQs

Selenium is one of the most important skills for QA Automation roles, but employers often expect additional knowledge such as Java or Python, TestNG, Maven, Jenkins, API testing, Git, and automation frameworks. A combination of these skills improves your job prospects significantly.

Yes, Selenium requires basic to intermediate programming knowledge. Since Selenium itself is a library, testers use programming languages such as Java, Python, C#, or JavaScript to write and execute automation scripts.

Manual testing involves executing test cases manually without tools, while Selenium automates repetitive test scenarios through scripts. Selenium improves test execution speed, accuracy, and reusability, making it suitable for regression and large-scale testing.

Selenium is primarily designed for web application testing and cannot directly automate native mobile apps. For mobile automation, testers commonly use Appium, which extends Selenium concepts to Android and iOS applications.

Learning Selenium can open roles such as Automation Test Engineer, QA Engineer, Software Development Engineer in Test (SDET), Test Automation Architect, and Quality Assurance Lead. Selenium is widely used across IT services, product companies, and startups.

Yes, Selenium continues to be one of the most widely used open-source automation testing tools. Organizations rely on Selenium for web application testing due to its flexibility, large community support, and compatibility with multiple programming languages and browsers.


Author

Aarthy R

Aarthy is a passionate technical writer with diverse experience in web development, Web 3.0, AI, ML, and technical documentation. She has won over six national-level hackathons and blogathons. Additionally, she mentors students across communities, simplifying complex tech concepts for learners.

Subscribe

Aarthy is a passionate technical writer with diverse experience in web development, Web 3.0, AI, ML, and technical documentation. She has won over six national-level hackathons and blogathons. Additionally, she mentors students across communities, simplifying complex tech concepts for learners.

Subscribe