Basic Questions
25 questions
1. What is Selenium and its main components?
Selenium is an open-source browser automation suite used for testing web applications across different browsers and operating systems. It helps teams simulate real user behavior such as opening routes, clicking elements, entering data, and validating what appears in the browser.
Its main components are Selenium IDE for simple recording, WebDriver for writing automation scripts in code, and Selenium Grid for parallel or distributed execution. Each component serves a different level of testing maturity, from quick experimentation to large-scale automation.
In real projects, WebDriver is usually the most important part because it gives teams full control over browser actions, validations, synchronization, and framework design. Selenium becomes most valuable when it is used as part of a broader automation strategy rather than as a standalone script runner.
2. What is Selenium WebDriver?
Selenium WebDriver is the main API used to automate browser behavior such as opening screens, clicking elements, entering values, and verifying results. It gives test code direct control over the browser in a way that is much closer to real user interaction than older record-and-playback approaches.
It works by sending commands to browser-specific drivers like ChromeDriver, GeckoDriver, or EdgeDriver through the W3C WebDriver standard. That standard helps keep behavior more consistent across modern browsers, even though each browser still has its own implementation details.
Compared with older Selenium tools, WebDriver is more stable, more flexible, and much better suited for building maintainable automation frameworks that run reliably in local and CI environments.
3. Differentiate between Selenium IDE, WebDriver, and Grid.
Selenium provides a suite of tools designed to address different testing needs. Selenium IDE, Selenium WebDriver, and Selenium Grid are used at different stages and complexity levels of test automation.
Selenium IDE is a record-and-playback tool mainly used by beginners. It allows testers to create test cases without writing code by recording browser actions. It is best suited for quick prototyping and simple test scenarios but is not ideal for complex or large-scale automation.
Selenium WebDriver is the core Selenium tool used for automating web applications through code. It supports multiple programming languages such as Java, Python, and JavaScript, and provides direct control over the browser. WebDriver is widely used in real-world automation frameworks and CI/CD pipelines.
Selenium Grid is used to run Selenium WebDriver tests in parallel across multiple machines, browsers, and operating systems. It helps reduce execution time and enables cross-browser and cross-platform testing at scale.
| Aspect | Selenium IDE | Selenium WebDriver | Selenium Grid |
|---|---|---|---|
| Type | Record and playback tool | Automation API or library | Distributed test execution tool |
| Coding Required | No or minimal | Yes | Yes, with WebDriver |
| Skill Level | Beginner | Intermediate to Advanced | Advanced |
| Browser Support | Limited | Wide, including Chrome, Firefox, and Edge | Wide, across connected nodes |
| Parallel Execution | No | Limited, with extra setup | Yes |
| Cross-Browser Testing | Limited | Yes | Yes, at scale |
| Best Use Case | Quick test creation and demos | Building robust automation frameworks | Large-scale parallel test execution |
| CI or CD Integration | Limited | Excellent | Excellent |
| Scalability | Low | Medium | High |
4. What are the different types of locators in Selenium?
Selenium supports several locator strategies, including id, name, className, tagName, linkText, partialLinkText, cssSelector, and xpath. Each one helps identify elements in the DOM, but the best choice depends on how stable and meaningful the markup is.
In real projects, stable IDs and clean CSS selectors are usually preferred because they are readable, fast, and easier to maintain. XPath is still very useful when the structure is complex, when element relationships matter, or when simpler selectors are not enough.
The main point is that a good locator is not just one that works today. It should also remain reliable when the UI changes slightly, so maintainability matters as much as technical correctness.
5. Explain implicit vs explicit waits.
In Selenium WebDriver, waits are used to handle synchronization issues caused by dynamic web applications. The two most commonly used waits are implicit wait and explicit wait, and they differ in scope, behavior, and reliability.
An implicit wait sets a global timeout for the entire WebDriver session. Once configured, Selenium will wait up to the specified time whenever it tries to locate any element before throwing a NoSuchElementException. This wait applies to every element lookup, which can lead to unnecessary delays if overused.
An explicit wait, on the other hand, is targeted and conditional. It waits for a specific condition to be met, such as element visibility, clickability, presence, or text change, before proceeding. Explicit waits are applied only where needed and provide much better control over test execution.
In real-world automation frameworks, explicit waits are preferred because they are precise, easier to debug, and handle dynamic UI behavior efficiently without slowing down the entire test suite.
| Aspect | Implicit Wait | Explicit Wait |
|---|---|---|
| Scope | Global, applies to all elements | Local, applies to specific elements |
| Configuration | Set once for the session | Defined per use case |
| Wait Condition | Only waits for element presence | Waits for specific conditions like visibility or clickability |
| Flexibility | Low | High |
| Impact on Test Speed | Can slow down the entire test run | More optimized and usually faster |
| Best Use Case | Simple or static applications | Dynamic, real-world applications |
| Industry Preference | Rarely used alone | Strongly preferred |
6. How do you launch different browsers in Selenium?
Different browsers are launched by creating the corresponding driver instance, such as ChromeDriver, FirefoxDriver, or EdgeDriver. At a basic level, that means choosing the correct browser driver and starting a session with the right configuration.
In stronger frameworks, the browser choice is not hardcoded. It is controlled through configuration files, environment variables, or runtime parameters so the same suite can run on different browsers without code changes. That becomes especially important in CI pipelines and cross-browser coverage strategies.
Teams also use browser options to enable headless mode, set download directories, pass startup arguments, or control preferences needed for specific test scenarios. Launching the browser is not just about opening it, but about starting the session in the exact state the test needs.
7. What is the difference between driver.get() and driver.navigate()?
In Selenium WebDriver, both driver.get() and driver.navigate() are used for browser navigation, but they serve slightly different purposes.driver.get() is a simple and direct way to open a URL. It loads the target screen and waits until the document is fully loaded before continuing execution. It is commonly used when the goal is simply to open a website or route.driver.navigate() returns a Navigation interface that provides more browser-like controls. Along with opening a URL using navigate().to(), it allows you to move backward and forward in the browser history and refresh the current screen. This makes it useful when the test scenario involves user-style navigation.
Internally, driver.get(url) and driver.navigate().to(url) behave almost the same when opening a route, but navigate() offers additional flexibility.
| Aspect | driver.get() | driver.navigate() |
|---|---|---|
| Purpose | Load a URL or screen | Perform browser navigation actions |
| Opens URL | Yes | Yes, using navigate().to() |
| Back or Forward | No | Yes |
| Refresh Page | No | Yes |
| Interface Returned | WebDriver | Navigation |
| Typical Usage | Initial route load | User-like navigation flow |
| Waiting Behavior | Waits for the document to load | Similar to get() for to() |
8. How do you handle alerts in Selenium?
Alerts are handled by switching the driver context to the alert using driver.switchTo().alert(). Once the alert is active, Selenium can accept it, dismiss it, read its message, or send input if it is a prompt dialog.
The important part is synchronization. Tests often fail not because alert handling is difficult, but because the code tries to switch to the alert before it appears or after it has already been handled. That is why explicit waiting for the alert condition is usually the safest approach.
The key idea is that alert handling is mainly about context and timing. Once the driver is switched correctly, the actual operations are straightforward.
9. Explain how to handle multiple windows or tabs.
Selenium identifies each browser window or tab with a unique window handle. The usual approach is to store the current window handle first, trigger the action that opens a new tab or window, then collect all handles and switch to the new one.
After finishing the required validation or action in the child window, the test should close it if needed and switch back to the original parent handle. This keeps the flow controlled and avoids confusion about which browser context is active.
The core idea is context management. The real skill is not just opening multiple windows, but moving between them safely and predictably so later steps still run in the right place.
10. What is Page Object Model (POM)?
Page Object Model, or POM, is a design pattern in which each screen, workflow, or major part of an application is represented by its own class. That class contains the important locators and the actions a user can perform there, such as logging in, filling a form, or submitting a search.
The main benefit is separation of concerns. Instead of mixing element selectors and UI interaction details directly inside the test case, the framework keeps that logic inside dedicated page or component classes. This makes tests easier to read and easier to maintain.
In real projects, POM reduces duplication and makes UI changes less expensive, because when a screen changes the update is usually made in one place instead of many test files.
11. What are the advantages of Selenium?
Selenium is one of the most widely used test automation tools because of its flexibility, ecosystem support, and cost effectiveness. It is especially suited for teams that want full control over their automation strategy.
One of the biggest advantages of Selenium is that it is open source, which means there are no licensing costs and it has a large global community contributing to continuous improvements and support. Selenium supports multiple browsers such as Chrome, Firefox, Edge, and Safari, and it works across different operating systems including Windows, macOS, and Linux. This makes it ideal for cross-browser and cross-platform testing.
Another major advantage is language flexibility. Selenium supports popular programming languages like Java, Python, JavaScript, C#, and Ruby, allowing teams to use the language they are already comfortable with. Selenium also integrates seamlessly with the modern testing ecosystem. It works well with testing frameworks like TestNG, JUnit, and Cucumber, CI or CD tools like Jenkins, and various reporting and build tools. This makes it easy to fit Selenium into real-world automation pipelines.
Finally, Selenium offers high flexibility. Teams can design and customize their own automation frameworks instead of being restricted by the limitations, pricing, or rigid workflows of commercial automation tools.
12. What are the limitations of Selenium?
Selenium is designed mainly for web browser automation, so it is not the right tool for desktop applications or most native mobile applications without additional tools. It also does not provide built-in reporting, test management, or visual validation as complete out-of-the-box features.
Another limitation is that Selenium gives flexibility, but that flexibility also means teams must design the framework carefully. Weak locators, poor synchronization, and unstable test data can quickly make the suite brittle even if the application itself works correctly.
The key takeaway is that Selenium is powerful, but it is not a complete testing platform by itself. Teams still need good framework design, supporting tools, and discipline around maintenance.
13. What is Selenium Grid and what is it used for?
Selenium Grid is used to run the same test suite in parallel across different browsers, operating systems, or machines. Instead of keeping all execution on one local machine, it distributes browser sessions across connected nodes or remote environments.
This becomes especially useful when a suite grows large and sequential execution starts taking too long. Grid helps reduce total runtime and makes it practical to validate the same product on multiple browser and platform combinations in the same pipeline.
In real projects, Grid is valuable not only for speed but also for environment coverage. It supports broader compatibility testing and helps teams move from single-machine execution to a more scalable execution model.
14. Explain driver.findElement() vs findElements().
Both methods are used to locate elements, but they behave differently based on what the test expects. findElement() is used when the test expects a single required element, and it returns the first matching WebElement. If nothing is found, Selenium throws a NoSuchElementException immediately.findElements() is used when multiple matches are possible or when the element may not be present at all. It returns a List<WebElement>, and if nothing matches, it simply returns an empty list. That makes it much safer for optional content, repeated structures, and defensive checks.
In practical terms, findElement() is better for mandatory elements like a login button, while findElements() is safer for optional checks, collections, menu items, or table rows. Choosing the right method makes test intent clearer and error handling more deliberate.
| Aspect | findElement() | findElements() |
|---|---|---|
| Return Type | Single WebElement | List of WebElement |
| Missing Element Behavior | Throws NoSuchElementException | Returns empty list |
| Best Fit | Required single element | Optional or repeated elements |
| Typical Use | Buttons, inputs, links | Rows, menus, collections |
15. How do you take screenshots in Selenium?
Screenshots are usually taken by casting the driver to TakesScreenshot and saving the captured output to a file. At the simplest level, this gives the framework a visual snapshot of the browser state at a specific moment in the test.
Most teams do not rely on manual screenshots. Instead, they automatically capture them on failures through listeners, hooks, or test lifecycle integrations so every important failure includes visual evidence without extra work from the test author.
Screenshots are especially helpful when debugging UI failures, locator issues, or unexpected interface states. When combined with logs, stack traces, and timing information, they provide much stronger failure evidence than plain text output alone.
16. What is TestNG and how is it used with Selenium?
TestNG is a testing framework commonly used with Selenium to manage execution flow, setup, teardown, grouping, parallel runs, and data-driven testing. It provides annotations such as @Test, @BeforeMethod, and @AfterMethod, which help structure the lifecycle of tests clearly.
Its value goes beyond simply running test methods. TestNG gives teams a way to organize suites, control order when needed, group related coverage, and integrate setup and cleanup behavior in a structured way.
In real Selenium frameworks, TestNG is often used not just for execution, but also for retries, parameterization, report integration, environment control, and organizing large regression suites. It becomes part of the framework architecture rather than just a runner.
17. How do you handle dropdowns in Selenium?
Handling dropdowns in Selenium depends first on what kind of dropdown the application is using. If it is a standard HTML select element, Selenium provides the Select class, which allows you to choose options by visible text, value, or index.
If the dropdown is custom-built using div, span, or JavaScript-driven components, then it has to be handled like normal UI interaction by clicking to open it and selecting the required option from the rendered list. In those cases, waits and locator quality become more important.
The first step is always identifying the DOM structure. The automation approach changes completely depending on whether the dropdown is native or custom.
18. What is the Actions class in Selenium?
The Actions class is used for advanced user interactions that go beyond simple element methods like click() or sendKeys(). It supports operations such as hover, drag and drop, double click, right click, click-and-hold, and keyboard combinations.
It becomes especially useful in modern applications with menus, sliders, layered components, and complex widgets where normal WebElement actions are not always enough. Because it builds interaction sequences, it can make the automation behave more like a real user.
It is most useful when the interface depends on richer mouse or keyboard behavior and standard element actions do not cover the whole interaction.
19. Explain synchronization in Selenium.
Synchronization means making sure the test interacts with the application only when the application is ready. Modern web applications often load data asynchronously, render in stages, or update the DOM after user actions, so tests can fail simply because they act too early even when the feature works correctly.
Good synchronization usually comes from explicit waits, stable conditions, and careful flow design. A reliable test should wait for something meaningful, such as visibility, clickability, state change, or loader completion, rather than assuming a fixed amount of time is enough.
Hardcoded sleeps should be avoided as much as possible because they make tests slower and less reliable. Strong synchronization improves both speed and trustworthiness at the same time.
20. What is headless browser testing?
Headless browser testing means running the browser without opening a visible user interface. The browser still executes JavaScript, loads styles, renders DOM updates, and behaves like a normal automated session, but without showing a window on screen.
This is especially useful in CI environments because it saves memory, reduces overhead, and can speed up large regression runs. It is also practical for containerized environments where there may be no desktop session available at all.
Teams often use headless mode for automated pipelines and switch to headed mode when debugging visual or interaction-related problems. The key idea is that headless mode changes visibility, not the fundamental purpose of browser automation.
21. How do you upload files in Selenium?
For a standard file upload control, the usual approach is to send the file path directly to the input element using sendKeys(). This works because Selenium interacts with the HTML file input itself rather than trying to control the operating system file picker.
That is an important distinction, because Selenium is designed for browser automation, not for native desktop dialog automation. As long as the input is a real file input, direct path injection is usually the most stable solution.
If the control is hidden or heavily customized, teams may need JavaScript assistance or small application-side changes. Still, direct sendKeys() remains the cleanest and most reliable upload method whenever possible.
22. What is the difference between close() and quit()?
close() shuts only the current browser window or tab, while quit() ends the complete WebDriver session and closes every browser window opened as part of that session. The difference matters because a test may work correctly in the current step but still leave browser resources behind if cleanup is incomplete.
In well-structured frameworks, quit() is usually called during teardown so all browser resources and driver processes are cleaned up properly. That is especially important in CI and parallel runs, where leftover sessions can create hidden instability.
If only close() is used at the end of a run, orphaned processes can remain and create unnecessary issues in later executions. The safe default for full test cleanup is usually quit().
| Aspect | close() | quit() |
|---|---|---|
| Scope | Current window or tab only | Entire browser session |
| Driver Session | Remains active if other windows exist | Ends completely |
| Best Use | Close one window during flow | Final teardown and cleanup |
| Risk if Misused | Can leave leftover processes | Ends all active browser work |
23. What is JavaScriptExecutor?
JavaScriptExecutor is an interface that allows Selenium to execute JavaScript directly inside the browser context. It is useful for tasks such as scrolling, interacting with difficult elements, reading values that are not easily exposed, or triggering browser-side behavior that normal WebDriver methods do not handle cleanly.
Even though it is powerful, it should not become the default answer for every UI problem. Overusing JavaScript can make tests less realistic because the automation may bypass the same interaction path a real user would take.
It works best as a targeted support tool. It is helpful when needed, but it should not replace strong locators, waits, and normal browser interactions.
24. How do you handle frames in Selenium?
Frames must be handled by switching the driver context into the frame before trying to interact with anything inside it. Selenium supports switching by index, name, ID, or WebElement depending on what is available. Without that context switch, even correct locators will fail because the driver is still looking at the outer document.
After finishing the required actions, the test should switch back to the default content or the parent frame so the next steps run in the correct browsing context. This is especially important when multiple frames or nested frames are involved.
A lot of frame-related failures happen not because the locator is wrong, but because the driver is in the wrong context. Strong frame handling is mostly about deliberate context management.
25. What are desired capabilities?
Desired capabilities were traditionally used to define browser and environment settings such as browser name, version, platform, and special execution properties, especially for remote runs. They helped tell WebDriver what kind of browser session should be created.
In Selenium 4, most teams now prefer browser-specific options classes such as ChromeOptions or FirefoxOptions because they are cleaner, more explicit, and better aligned with modern browser setup. Still, the core idea remains the same.
They are best understood as part of browser session configuration. Even though the syntax has evolved, the purpose is still to control how the WebDriver session is launched and managed.