Selenium Interview Q&A
Q1. What is Selenium? What are its components?
A: Selenium is an open-source automation testing tool for web applications. Its main components are:
-
Selenium IDE – Record & playback tool.
-
Selenium RC (deprecated) – Older client-server architecture.
-
Selenium WebDriver – Modern, widely used API for browser automation.
-
Selenium Grid – Parallel test execution across multiple machines/browsers.
Q2. Difference between Selenium WebDriver and Selenium RC?
A:
-
WebDriver directly communicates with the browser using native API → faster & more efficient.
-
RC used a server as a middle layer → slower & deprecated.
Q3. Which programming languages are supported by Selenium?
A: Java, Python, C#, Ruby, JavaScript, Kotlin, etc. (Most common: Java & Python).
WebDriver Basics
Q4. How do you launch a browser in Selenium WebDriver?
A (Java Example):
Q5. Difference between driver.close() and driver.quit()?
-
driver.close() → Closes current active browser window.
-
driver.quit() → Closes all browser windows opened by WebDriver and ends the session.
Q6. How do you locate elements in Selenium?
A: Using locators:
-
id
-
name
-
className
-
tagName
-
linkText / partialLinkText
-
cssSelector
-
xpath
Example:
Waits & Synchronization
Q7. What is the difference between Implicit Wait and Explicit Wait?
-
Implicit Wait → Sets a default waiting time for all elements.
-
Explicit Wait → Waits for a specific condition for a specific element.
Example (Explicit Wait in Java):
Q8. What is Fluent Wait in Selenium?
A: It checks for a condition at regular intervals until timeout. It allows polling frequency & ignoring exceptions.
Practical Questions
Q9. How do you handle dropdowns in Selenium?
A (Java Example):
Q10. How do you handle alerts/popups in Selenium?
Q11. How do you handle multiple browser windows?
Q12. How do you perform mouse hover or drag-and-drop in Selenium?
Advanced Questions
Q13. What is Page Object Model (POM)?
A: A design pattern in Selenium that creates separate classes for each page, storing locators and methods.
It improves reusability & maintainability.
Q14. How do you handle dynamic elements in Selenium?
-
Use XPath with contains(), starts-with()
-
Use CSS selectors with partial attributes
Example:
Q15. How do you capture screenshots in Selenium?
Q16. How do you run Selenium tests in parallel?
-
Using TestNG
parallel=tests or parallel=classes
-
Using Selenium Grid
Q17. What are limitations of Selenium?
-
Supports only web applications (not desktop apps).
-
Cannot automate Captcha, OTP, Barcode directly.
-
No inbuilt reporting → Need tools like TestNG/Allure/Extent Reports.
-
No direct support for image comparison.
Behavioral / Experience-Based
Q18. Tell me about your Selenium framework.
👉 Answer should cover:
-
Framework type: Hybrid / Data-driven / Keyword-driven / POM + TestNG
-
Features used: Maven/Gradle for dependencies, TestNG for test management, Extent/Allure for reporting, Jenkins for CI/CD, Git for version control.
Q19. What challenges did you face in Selenium automation?
Examples you can mention:
-
Handling dynamic elements (solution: smart XPath/CSS).
-
Browser compatibility issues (solution: Selenium Grid).
-
Synchronization issues (solution: Explicit/Fluent waits).
-
Test data management (solution: Excel/CSV/Database integration).
Q20. How do you integrate Selenium with CI/CD?
-
Use Jenkins/GitHub Actions to trigger builds.
-
Configure Maven commands:
mvn clean test.
-
Generate reports after test execution.
Intro
Interviewer: Tell me about yourself.
You (Sample Answer):
“I have 2 years of experience in software testing, with a focus on automation using Selenium WebDriver and manual testing. I have worked on web applications across [domain – e.g., healthcare, e-commerce]. My skills include test case design, defect reporting, API testing with Postman, and automation framework development using Selenium with TestNG. I have also integrated my scripts with Jenkins for CI/CD and generated reports using Extent/Allure. I’m comfortable with Agile methodology and actively participated in sprint planning and daily standups.”
Core Selenium
Interviewer: What is Selenium WebDriver, and how is it different from Selenium RC?
You:
“Selenium WebDriver is a tool used to automate browser actions. It communicates directly with the browser using native APIs. Unlike Selenium RC, WebDriver does not need a server in between, which makes it faster and more efficient. Selenium RC is now deprecated, and WebDriver is widely used.”
Interviewer: What locators have you used most often? Which one do you prefer?
You:
“I mostly use XPath and CSS selectors for dynamic elements, but I prefer id or name when available since they are faster and more reliable. If the attributes are dynamic, I use XPath functions like contains(), starts-with(), or CSS with partial matches.”
Interviewer: What is the difference between driver.close() and driver.quit()?
You:
“driver.close() closes only the current active browser window, while driver.quit() closes all browser windows opened by WebDriver and ends the session.”
Waits & Synchronization
Interviewer: How do you handle synchronization issues in Selenium?
You:
“I use different types of waits. For general waits, I use implicit wait. For specific conditions, I use explicit wait with WebDriverWait and ExpectedConditions. If I need polling intervals or to ignore exceptions, I use FluentWait. This helps avoid NoSuchElementException or ElementNotInteractableException.”
Practical Coding
Interviewer: Can you write a snippet to select a value from a dropdown?
You (Java Example):
Interviewer: How would you handle multiple browser windows?
You:
Framework & Tools
Interviewer: Can you explain your Selenium automation framework?
You:
“My framework is a Hybrid framework combining Page Object Model and Data-Driven approach. I use Maven for dependency management, TestNG for test execution, and Extent/Allure for reporting. I have utilities for reading data from Excel and property files. For CI/CD, I integrated it with Jenkins to trigger test runs automatically. The framework supports parallel execution using TestNG and Selenium Grid.”
Interviewer: How do you manage test data in your automation framework?
You:
“I maintain test data in Excel/CSV files and sometimes in property files for configuration values. I also parameterize tests using TestNG @DataProvider. This helps in reusing the same script with multiple sets of data.”
Challenges
Interviewer: What challenges did you face in Selenium automation, and how did you solve them?
You (Sample Examples):
-
Dynamic elements: Solved using robust XPath with
contains() or CSS partial selectors.
-
Page load delays: Used explicit waits like
visibilityOfElementLocated.
-
Cross-browser issues: Used Selenium Grid to test in different browsers.
-
Large test execution time: Implemented parallel execution with TestNG.
CI/CD
Interviewer: How do you integrate Selenium tests with Jenkins?
You:
“I created a Jenkins job where I linked our GitHub repository. I configured Maven commands like mvn clean test in the build step. After execution, the job generates Extent/Allure reports, which are published as part of Jenkins build results. This setup ensures automation tests run automatically after every code push.”
Behavioral
Interviewer: Why should we hire you?
You:
“I bring hands-on experience in both manual and automation testing. I have built and executed automation frameworks with Selenium and TestNG, handled challenges with dynamic applications, and worked in Agile teams. With my 2 years of experience, I can quickly contribute to automation efforts, improve test coverage, and help in delivering quality products.”
Must-Practice Selenium Coding Tasks
1. Launch Browser & Open URL
-
Open Chrome/Firefox
-
Navigate to Google
-
Maximize window & print the page title
2. Locating Elements
-
Locate by id, name, class, CSS, XPath
-
Example: search box on Google, login fields on a demo site
3. Login Automation
-
Open login page
-
Enter username, password
-
Click Login button
-
Validate successful login using
assert on page title / welcome message
4. Handling Dropdowns (Using Select class)
-
Select by index, value, visible text
-
Example: select “India” from a country dropdown
5. Handling Checkboxes & Radio Buttons
-
Select a checkbox → verify it is selected
-
Select a radio button → verify mutual exclusivity
6. Handling Alerts/Popups
-
Simple alert →
accept()
-
Confirmation alert →
dismiss()
-
Prompt alert →
sendKeys("text")
7. Handling Multiple Windows/Tabs
-
Click link that opens a new tab
-
Switch to child window → perform action
-
Switch back to main window
8. Handling Frames/iFrames
-
Switch to frame by index, name, or WebElement
-
Perform action inside frame
-
Switch back to default content
9. Mouse & Keyboard Actions (Actions Class)
-
Mouse hover (moveToElement)
-
Drag & drop
-
Double click
-
Right click (context click)
-
Send keys with
Keys.ENTER
10. Waits (Synchronization)
-
Implicit wait example
-
Explicit wait → wait for element to be clickable
-
Fluent wait → with polling interval
11. Working with Web Tables
-
Find number of rows & columns
-
Read data from a specific cell
-
Iterate through all rows & print values
12. Handling Dynamic Elements
-
Write XPath with
contains(), starts-with(), last(), following-sibling
-
Example: selecting a search suggestion from Google auto-suggest list
13. File Upload
-
Use
sendKeys("path/to/file") on <input type="file">
-
Or handle OS pop-up with Robot class / AutoIt (if asked)
14. Screenshot Capture
-
Take screenshot on failure
-
Save with dynamic filename (timestamp)
15. Data-Driven Testing (DDT)
-
Use TestNG
@DataProvider
-
Read data from Excel (Apache POI)
-
Run the same test with multiple inputs
16. Page Object Model (POM) Implementation
-
Create separate class for each page
-
Store locators & methods inside page classes
-
Use them in test class
17. Parallel Execution
-
Run 2–3 tests in parallel using TestNG XML
-
Example: login test + search test
18. End-to-End Flow Automation
-
Open e-commerce site (like demo.opencart, saucedemo, or Amazon)
-
Search product → Add to cart → Checkout → Validate order success
19. Reporting
-
Integrate Extent Reports or Allure
-
Generate a test execution report
20. Jenkins Integration
-
Create a Maven project
-
Run
mvn clean test
-
View test results in Jenkins
Selenium 20 Coding Tasks with Answers (Java + Selenium)
1. Launch Browser & Open URL
2. Locating Elements
3. Login Automation
4. Handling Dropdowns
5. Handling Checkboxes & Radio Buttons
6. Handling Alerts
7. Handling Multiple Windows
8. Handling Frames/iFrames
9. Mouse & Keyboard Actions
10. Waits
11. Web Tables
12. Handling Dynamic Elements
13. File Upload
14. Screenshot Capture
15. Data-Driven Testing (TestNG + DataProvider)
16. Page Object Model (POM)
17. Parallel Execution (TestNG XML)
18. End-to-End Flow
19. Reporting (Extent Reports Example)
20. Jenkins Integration
-
Push project to GitHub (Maven + TestNG).
-
Jenkins → Create job → Configure Git repo.
-
In Build Step → use:
-
Post-build → Publish HTML/Extent reports.
Project Structure
📄 pom.xml (Dependencies)
📄 testng.xml
📄 pages/LoginPage.java
📄 utils/ExtentManager.java
📄 tests/LoginTest.java
Run Instructions
-
Clone project from GitHub (or create new Maven project).
-
Run tests with:
-
Open report: