Easy Level Questions:
1. What is Selenium?
Selenium is an open-source suite of tools for automating web browsers.
It lets you write scripts that interact with web pages to test functionality,
regression, and UI workflows.
2. What are the components of Selenium?
Main components: Selenium WebDriver (browser automation API),
Selenium IDE (record/replay), Selenium Grid (distributed/parallel
execution). Historically there's also Selenium RC (deprecated).
3. Difference between Selenium 2 (WebDriver) and Selenium 3/4?
Selenium 2 introduced WebDriver (a cleaner API than RC). Selenium 3
stabilized WebDriver and removed RC. Selenium 4 adds W3C
WebDriver compliance, enhanced DevTools (CDP) integration,
improved relative locators, and better support for modern browsers.
4. What is Selenium WebDriver?
WebDriver is the language-specific API that controls browsers by
sending commands to the browser’s driver binary
(chromedriver/geckodriver). It models browser elements as
WebElement objects and performs user-like actions.
5. What are the different types of locators in Selenium?
ID, name, className, tagName, linkText, partialLinkText, CSS selector,
XPath. Use the most specific and stable locator (ID > CSS > XPath
typically).
6. Why is XPath used? Difference between absolute and relative
XPath?
XPath is useful for complex DOM traversal and when attributes are
limited. Absolute XPath starts from the root (/html/...) and is fragile;
relative XPath (//div[@class='x']) is preferred and more resilient.
7. What is CSS Selector? How is it different from XPath?
CSS selectors select elements using CSS rules (e.g., [Link] > a#id).
They’re usually faster and more readable; XPath is more powerful for
traversing up the DOM and using functions/axes.
8. What is the difference between findElement() and
findElements()?
findElement() returns the first matching WebElement and throws
NoSuchElementException if none found. findElements() returns a
List<WebElement> (empty list if no matches).
9. How do you launch different browsers in Selenium?
Set up the corresponding driver
(chromedriver/geckodriver/IEDriverServer) or use WebDriverManager,
then create browser-specific driver objects (e.g., new ChromeDriver()).
10. What is WebDriverManager? Why do we use it?
WebDriverManager (by bonigarcia) automatically downloads and
manages browser driver binaries, matching browser versions — avoids
manual driver download/configuration.
11. What is the difference between [Link]() and [Link]()?
close() closes the current browser window; quit() closes all windows
and ends the WebDriver session (recommended in teardown).
12. How do you maximize a browser window using Selenium?
[Link]().window().maximize();
13. How to handle dropdowns in Selenium?
Use Select class for <select> elements (new Select(element)) —
methods: selectByVisibleText(), selectByValue(), selectByIndex();
otherwise use click/select and custom locators for custom dropdowns.
14. Difference between getText() and getAttribute()?
getText() returns visible inner text of an element. getAttribute() returns
the value of a specified attribute (e.g., value, href, class).
15. How do you handle checkboxes and radio buttons in Selenium?
Locate the element and use click() or isSelected() to check state; for
controlled components check attributes or underlying input value.
16. What is implicit wait?
Implicit wait sets a default polling timeout for findElement() calls —
the driver polls until an element appears or timeout occurs. It's global
and can cause unpredictable waits with other explicit waits.
17. What is explicit wait?
Explicit wait (e.g., WebDriverWait) waits for a specific condition for a
given element or state (visibility, clickable, presence, etc.). It's targeted
and more reliable than implicit waits.
18. Why is [Link]() discouraged in automation?
[Link]() is a static wait: it blocks the thread for a fixed time and is
inefficient and brittle. Prefer explicit waits that wait for conditions.
19. What is a WebElement?
WebElement is an interface representing an element on the page; it
exposes methods like click(), sendKeys(), getText(), getAttribute().
20. What is Page Load Timeout?
[Link]().timeouts().pageLoadTimeout([Link](x))
sets max time to wait for a page to load before throwing an exception.
21. How do you navigate between pages using Selenium?
Use [Link]().to(url), navigate().back(), navigate().forward(),
navigate().refresh().
22. How do you get the title of the page?
[Link]() returns the current page title string.
23. How do you get the current URL?
[Link]().
24. How can you check if a WebElement is
displayed/enabled/selected?
Use [Link](), [Link](), [Link]().
25. What are the different types of exceptions in Selenium?
Common ones: NoSuchElementException,
StaleElementReferenceException, TimeoutException,
ElementNotInteractableException, ElementClickInterceptedException,
WebDriverException.
26. What is StaleElementReferenceException?
Occurs when the DOM changes and a previously found WebElement no
longer points to a current element — re-locate the element or re-find it.
27. How do you take a screenshot in Selenium?
Use TakesScreenshot interface: File src =
((TakesScreenshot)driver).getScreenshotAs([Link]); then
save.
28. What is the use of Actions class in Selenium?
Actions enables complex user interactions: mouse hover, drag-and-drop,
double-click, right-click, key modifiers, and composite sequences.
29. How do you perform mouse hover in Selenium?
new Actions(driver).moveToElement(element).perform();
30. How to upload a file using Selenium?
For <input type="file"> send the file path:
[Link]("/path/to/file"). For custom upload widgets, use OS-
level automation (Robot, AutoIt) or interact with the upload API.
Moderate Level Questions
31. Difference between implicit wait and explicit wait?
Implicit wait applies globally to findElement calls; explicit wait targets
a specific element/condition. Mixing them can cause unexpected
behavior — prefer explicit waits.
32. What is FluentWait?
FluentWait is a customizable explicit wait with polling frequency and
ignored exceptions configuration, useful when you need fine-grained
control.
33. How do you handle multiple windows in Selenium?
Use [Link]() to get all handles, iterate,
[Link]().window(handle) to change context, and
[Link]()/[Link]() appropriately.
34. How to switch to an iframe in Selenium?
[Link]().frame(index or name or WebElement) and to return:
[Link]().defaultContent() or parentFrame().
35. What is a WebDriverWait? Give an example.
WebDriverWait wait = new WebDriverWait(driver,
[Link](10));
[Link]([Link](element)); — waits until the
condition is true.
36. How do you handle JavaScript alerts in Selenium?
Switch to alert: Alert alert = [Link]().alert(); then [Link](),
[Link](), [Link](), [Link]().
37. How do you scroll a page in Selenium?
Use JavascriptExecutor:
((JavascriptExecutor)driver).executeScript("[Link](0,500)");
or scroll to element arguments[0].scrollIntoView(true).
38. How to execute JavaScript using Selenium?
JavascriptExecutor js = (JavascriptExecutor) driver;
[Link]("return [Link]");
39. What is JavaScriptExecutor?
Interface that allows executing JS in browser context for operations not
exposed by WebDriver (DOM manipulation, retrieving computed
values, shadow DOM access via JS).
40. What is the difference between submit() and click()?
submit() submits a form (works when element is within a form). click()
simulates clicking an element (button, checkbox, link).
41. Explain Page Object Model (POM).
POM is a design pattern where each page has a corresponding class
encapsulating element locators and actions, promoting maintainability
and reusability.
42. What is PageFactory?
PageFactory is a Selenium helper that initializes @FindBy annotated
fields for POM using [Link](driver, this) to reduce
boilerplate locating code.
43. What is a data-driven framework?
A framework that separates test data from test scripts (data from
Excel/CSV/JSON/DB), running the same test logic with multiple
datasets.
44. Difference between POM and Page Factory?
POM is the pattern; PageFactory is an implementation convenience for
initializing elements in POM using annotations like @FindBy.
45. How do you run tests in parallel?
Use TestNG parallel execution in [Link]
(parallel="methods"|"classes"|"tests" plus thread-count) or parallel
runners in build tools/CI. Ensure thread-safe WebDriver management
(ThreadLocal).
46. What is TestNG?
TestNG is a Java testing framework with annotations, flexible test
configuration, data providers, parallel execution, and built-in reporting.
47. Difference between JUnit and TestNG?
TestNG offers broader features (data-driven tests with @DataProvider,
@BeforeSuite, flexible test grouping and parallelism) while JUnit is
simpler; both can be used but TestNG is common in Selenium projects.
48. What is the use of annotations in TestNG?
Annotations (@Test, @BeforeTest, @AfterMethod, etc.) define test
lifecycle hooks and control the order and configuration of test
execution.
49. Explain the [Link] structure.
[Link] defines suites, tests, classes, methods, parameters, groups,
and parallelization settings to configure TestNG runs.
50. How do you generate HTML reports in TestNG?
TestNG produces default HTML reports. For enhanced reports use
ExtentReports or Allure integrated via listeners or test hooks.
51. What are Listeners in TestNG?
Listeners are interfaces (ITestListener, ISuiteListener) that let you
respond to test events (onStart, onFinish, onTestFailure) to add logging,
reporting, screenshots, etc.
52. What is RetryAnalyzer in TestNG?
A mechanism to re-run failed tests automatically by implementing
IRetryAnalyzer and configuring it on tests to reduce transient failures.
53. What is SoftAssert vs HardAssert?
Hard Asserts ([Link]) stop test execution on failure.
SoftAssert collects failures and allows the test to continue, then
assertAll() reports aggregated failures.
54. How do you validate broken links using Selenium?
Collect link URLs (<a> tags), send HTTP HEAD/GET requests via
HttpURLConnection or Apache HttpClient, and assert response codes
(e.g., 200 OK vs 404/500).
55. How do you validate a tooltip using Selenium?
Hover the element ([Link]) and read tooltip either via
getAttribute("title") if static or by locating the tooltip element in DOM
after hover and calling getText().
56. How do you handle dynamic elements in Selenium?
Use stable locators (IDs, data-* attributes), relative XPaths, explicit
waits, or strategies like locating parent elements and then children;
avoid brittle absolute paths.
57. What is a Shadow DOM? How do you handle it?
Shadow DOM encapsulates DOM subtree and styles. You access
shadow roots via JS ([Link]) or Selenium’s shadow DOM
API (if available) / JavascriptExecutor to query inside shadow trees.
58. What is the difference between WebDriver and
RemoteWebDriver?
RemoteWebDriver is used to send commands to a remote server (Grid
or Selenium server). ChromeDriver/FirefoxDriver are local driver
implementations extending RemoteWebDriver.
59. How do you perform drag-and-drop in Selenium?
Use Actions:
[Link](source).moveToElement(target).release().perform
(); or JS-based workarounds if HTML5 drag/drop fails.
60. How to handle authentication popups?
For basic auth, include credentials in URL ([Link] or
use browser profiles/auto-auth extensions. For OS-level dialogs, use
Robot/AutoIt or use DevTools protocol to set auth headers.
61. Why do we use Maven/Gradle in automation?
They manage build lifecycle and dependencies, provide plugins for
running tests, and integrate with CI systems — making project setup
and dependency resolution repeatable.
62. What is a build management tool?
A tool (Maven/Gradle) that builds code, resolves dependencies, runs
tests, packages artifacts, and executes plugins for tasks like reports.
63. What are dependencies in Maven?
Dependencies are external libraries declared in [Link] which Maven
downloads from repositories and adds to the project classpath.
64. What is a DOM?
DOM (Document Object Model) is an in-memory representation of the
HTML document as a tree of nodes that scripts and automation interact
with.
65. Difference between [Link]() and [Link]()?
get() and navigate().to() both load a URL; navigate() provides additional
navigation methods (back, forward, refresh) and can be more flexible
for history operations.
66. Explain method overloading and overriding in Java (relevant to
framework design).
Overloading: same method name, different parameter lists (compile-
time polymorphism). Overriding: subclass provides implementation for
a superclass method (runtime polymorphism). Useful for reusable
helper methods and customizations.
67. What is the difference between HashMap and Hashtable (used
in data storage)?
HashMap is non-synchronized and allows null keys/values. Hashtable is
synchronized (legacy) and doesn’t allow nulls. Prefer
ConcurrentHashMap for thread-safe, high-performance concurrent use.
68. Why do we use OOP principles in automation framework?
OOP promotes modularity, reuse, encapsulation, and maintainability —
making frameworks easier to extend and reducing duplication.
69. Explain Singleton design pattern in the context of WebDriver.
A Singleton ensures only one instance of WebDriver in the test context
(often via private constructor and a static getInstance()), but in parallel
runs use ThreadLocal singletons to avoid cross-thread sharing.
70. Why is Selenium not suitable for desktop application
automation?
Selenium controls web browsers only — it cannot interact with native
OS GUI elements; tools like WinAppDriver, AutoIt, or Sikuli are used
for desktop apps.
Difficult Level Questions
71. How do you design a complete Selenium automation framework
from scratch?
Key pieces: project structure (src/test/java, resources), POM or BDD
pattern, driver factory, configuration management (properties/JSON),
test data layer, page objects, utilities (waits, logging, screenshots),
reporting (Extent/Allure), CI integration, and test orchestration with
TestNG. Start small, enforce coding standards, and add features
iteratively.
72. Explain Page Object Model + Page Factory + TestNG + Maven
integration.
POM organizes pages as classes; PageFactory initializes @FindBy
elements; TestNG handles test execution and annotations; Maven
manages dependencies and test runs via mvn test. Combine them: pages
in src/main, tests in src/test, TestNG XML controls test suites, and
Maven surefire runs tests.
73. What is hybrid framework architecture?
Hybrid combines multiple approaches (data-driven + keyword-driven +
modular) so testers can write tests using keywords or code and reuse
data and modules for different scenarios.
74. Explain keyword-driven frameworks with an example.
Keyword-driven frameworks use a table (Excel/CSV) describing actions
(keywords) and targets; framework maps keywords like CLICK,
ENTER_TEXT to code methods and executes steps based on the sheet,
enabling non-developers to write tests.
75. How do you implement logging in a Selenium framework?
Use logging libraries (Log4j2, SLF4J) to record steps, driver
initialization, errors, and diagnostics. Configure appenders, log levels,
and include logs with test reports and CI artifacts.
76. What is the role of Log4j or SLF4J in Selenium?
They provide structured logging (levels, formatting), centralizing debug
and runtime information for troubleshooting and audits.
77. How do you integrate Extent Reports or Allure Reports?
Add dependencies, set up listeners to capture test events, take
screenshots on failure, and attach data. Configure report initialization in
@BeforeSuite and flush in teardown.
78. What is Selenium Grid? Explain Hub and Node.
Grid allows distributed execution. Hub is the central server receiving
tests; Nodes are machines (or containers) registered to the hub that run
browsers. Tests sent to hub are routed to compatible nodes.
79. How do you run tests in parallel on Selenium Grid?
Configure TestNG parallelism and desired capabilities that match node
capabilities; start several nodes (or containers) with different browser
versions; submit parallel tests, Grid routes them to free nodes.
80. What is Docker Selenium?
Pre-built Docker images (Selenium standalone and grid) that run
browsers in containers, enabling consistent and isolated environments
for distributed tests.
81. How do you run Selenium tests inside Docker containers?
Use Docker images for the Grid or standalone browsers, ensure the test
runner can reach the Grid endpoint (networking), and mount artifacts;
CI pipelines spin up containers, run tests, collect reports, then tear
down.
82. How do you manage test data in a framework (JSON, Excel, DB,
YAML)?
Store test data in external files or DBs and abstract access through a
data provider layer. Use @DataProvider in TestNG to feed tests with
datasets from Excel/CSV/JSON or DB queries.
83. How can you integrate CI/CD pipelines (Jenkins/GitHub
Actions) with Selenium tests?
Configure CI jobs/pipelines to check out code, run Maven/Gradle tests,
start required services (Grid, Docker), collect and archive
reports/snapshots, and trigger runs on commits or PRs.
84. What is headless browser testing?
Running browsers without a visible UI (headless Chrome/Firefox) for
faster execution and resource efficiency, useful for CI. However some
behaviors differ from headed mode — validate critical tests in headed
mode too.
85. Difference between ChromeOptions and DesiredCapabilities?
ChromeOptions is browser-specific configuration (arguments, prefs).
DesiredCapabilities was a generic capability container; modern usage
favors Options classes and W3C-compliant capabilities merging.
86. How to handle web tables (static and dynamic) in Selenium?
Locate rows/columns via XPath/CSS, loop through rows
List<WebElement> rows = [Link]([Link]("tr")), parse
cells, or write helper methods to search by cell text or headers.
87. How do you automate pagination in Selenium?
Locate and iterate pagination controls (next page link or page numbers),
use loops with explicit waits after navigation, and aggregate/validate
data across pages.
88. What is the Robot class? Why is it used?
[Link] simulates OS-level keyboard/mouse events for non-web
dialogs or native interactions (file chooser, print dialog). Use only when
browser-level APIs cannot interact.
89. How do you bypass reCAPTCHA in automation? (Trick
question → You should NOT automate).
You should never bypass reCAPTCHA in production; use test keys,
mock/stub reCAPTCHA in test environments, or disable it via
configuration for test domains. Bypassing CAPTCHA on prod is against
terms and unethical.
90. What is event firing WebDriver?
EventFiringWebDriver (or WebDriver event listeners) intercept
WebDriver events to log actions, take screenshots on failure, or add
custom behavior. Note: implementations vary — use WebDriverListener
(Selenium 4) or custom listeners.
91. How do you capture network logs in Selenium?
Use browser DevTools Protocol (CDP) via Selenium 4 DevTools to
capture network requests/responses, or use a proxy (BrowserMob
Proxy) to intercept traffic.
92. How do you capture console logs in Selenium?
Retrieve browser logs:
[Link]().logs().get([Link]); or use DevTools/CDP
for richer console/Network events.
93. Explain the concept of waits internally (Polling mechanism).
Explicit waits poll the DOM at a configurable interval until a condition
is met or timeout; this reduces wasted time vs fixed sleeps. The poll
interval and ignored exceptions control responsiveness.
94. How do you debug flaky Selenium tests?
Collect logs, screenshots/videos, reproduce locally, isolate
timing/dynamic content issues, add robust waits, avoid brittle locators,
examine environment differences, and run multiple times to identify
intermittent causes.
95. What is a race condition in Selenium automation?
A race condition occurs when the test proceeds before the application or
element is ready (e.g., asynchronous calls), producing inconsistent
results. Fix with explicit waits or synchronization mechanisms.
96. How do you handle WebDriver synchronization issues?
Use explicit waits, wait for specific conditions (element
clickable/visible), avoid implicit waits or long static sleeps, and design
tests to wait for application events or network idle state.
97. Explain the internal architecture of Selenium WebDriver.
WebDriver API sends commands to browser-specific drivers
(chromedriver, geckodriver) via JSON over HTTP/WebSocket. The
driver translates commands into browser actions. Selenium client
libraries wrap API calls.
98. What is W3C WebDriver Protocol?
A standardized protocol for browser automation commands over HTTP,
ensuring consistent behavior across browsers and reducing vendor-
specific differences.
99. How will you automate an Angular or React based application
(handling shadow DOM, dynamic waits)?
Use explicit waits for Angular/react lifecycle (wait for XHR/promise
completion), use locators tied to stable attributes, for shadow DOM use
JS or Selenium shadow APIs, and leverage tools like Protractor
alternatives or inspecting DevTools for stable hooks.
100. Explain the most challenging automation problem you solved
and your approach.
(Sample answer structure) Problem: flaky tests on dynamic content due
to lazy loading. Approach: added explicit waits for network idle via
DevTools, refactored locators to resilient attributes, introduced retry for
transient failures, and added logging/screenshots — result: 90%
reduction in flakes. — Give your own real example in interviews.