Selenium with Java interview questions often begin with this one. Selenium is a free, open-source tool used to test web applications by automating browsers. With Java, it becomes one of the most popular choices for automation testing because it is reliable, easy to use, and works across different browsers and platforms.
Selenium has four parts:
Advantages: It is free, supports many programming languages, works with all major browsers, and has strong community support.
Limitations: It works only for web applications, not for mobile or desktop. It also does not have built-in reporting or support for image-based testing.
It supports Java, Python, C#, JavaScript, Ruby, PHP, and Kotlin. Among these, Java is most widely used in India for automation projects.
Java is popular in IT companies, has strong documentation, a wide support community, and works well with Selenium frameworks. Many companies also already use Java for development, so it is a natural choice for automation.
Selenium 4 follows international standards for browser automation, which improves reliability. It has new features like relative locators, an improved Selenium Grid, and better debugging tools.
No. Selenium is designed only for web applications. For desktop apps, separate tools like AutoIt or Winium are used.
It supports major browsers including Chrome, Firefox, Edge, Safari, Opera, and Internet Explorer.
Selenium IDE is for record and playback, mainly for simple tests. Selenium RC was older and slower, needing a server to run. WebDriver is the advanced version, directly interacting with browsers and is the industry standard today.
Selenium Grid allows parallel execution of tests on multiple machines and browsers. This reduces execution time and helps ensure the application works in different environments.
The equality operator checks if two objects point to the same memory. The equals method checks if two objects have the same value. In automation, we often compare values, not memory references.
Object-Oriented Programming includes encapsulation, inheritance, polymorphism, and abstraction. For example, test frameworks use encapsulation in page classes, inheritance to reuse base methods, polymorphism to perform actions in different ways, and abstraction to hide technical details.
An ArrayList stores data in a sequence where each item has an index. A HashMap stores data as key-value pairs, which is useful when you want to look up values by a unique key.
They define the visibility of classes, methods, and variables. Public means it can be accessed anywhere, private means only inside the class, protected allows access in the same package and subclasses, and default is limited to the same package.
Final is used to make variables constant or prevent changes to classes and methods. Finally is a block of code that always runs after a try-catch, usually for cleanup. Finalize is a method called before an object is destroyed by the system.
Exceptions are errors that occur during execution, such as missing files or invalid inputs. They are handled using try-catch blocks so that the program can continue running even after an error.
Throw is used to actually raise an exception in the program. Throws is used in a method declaration to indicate that the method might raise certain exceptions.
Polymorphism means one action can be performed in different ways. In automation, it allows you to design methods that can handle different test situations using the same method name.
Static belongs to the class itself rather than individual objects. They are often used for common data like file paths or reusable utility functions that do not change for each object.
Inheritance lets one class reuse the properties and methods of another. In frameworks, a base class may contain browser setup or reporting functions, and test classes inherit these features instead of rewriting them.
Selenium WebDriver is the most commonly used tool in the Selenium suite. It allows direct communication with the browser to perform actions like clicking, typing, and navigating. Unlike older tools, it does not require any intermediate server, making it faster and more reliable.
FindElement locates a single element on the page and returns the first match. FindElements searches for multiple elements and returns a list. If no element is found, FindElement gives an error, but FindElements gives an empty list.
When a website opens a new tab or window, Selenium provides unique identifiers for each window. We switch between these identifiers to interact with different windows during automation.
Popups like alerts and confirmations can be controlled by switching the focus of Selenium to the popup. Then we can accept, dismiss, or read the text from it.
Dropdowns can be handled by selecting an option either by visible text, by value, or by position. Selenium provides dedicated methods for this, making it easy to work with dropdown menus.
Drag-and-drop actions are done using special classes in Selenium that allow handling of advanced user actions. We specify the source element and the target element, and then perform the drag-and-drop action.
Dynamic elements change their properties, like IDs, every time the page loads. To handle them, we use flexible ways of locating elements such as partial attributes, relative positions, or logical conditions instead of fixed values.
Selenium allows capturing the current view of the browser. This is useful for debugging or reporting test results when a test fails.
GetWindowHandle returns the identifier of the current browser window. GetWindowHandles returns a set of all open windows, allowing switching between them.
TestNG is a testing framework that organizes and runs test cases. With Selenium, it is used for structuring tests, grouping them, running them in parallel, and generating reports.
Both are testing frameworks. JUnit is older and simpler, while TestNG offers more advanced features like test grouping, dependencies, and parallel execution. Most companies prefer TestNG with Selenium.
In TestNG, test cases are created using annotations. These annotations define the flow of execution, making it easier to organize and maintain test cases.
TestNG allows tests to be executed simultaneously by defining the parallel setting in its configuration file. This helps reduce total execution time.
Annotations are markers that control how and when test methods run. For example, some annotations run before all tests, some after each test, and others only for specific groups of tests.
TestNG automatically creates HTML and XML reports after execution. These reports show the number of tests passed, failed, or skipped.
POM is a design pattern where each page of the application is represented as a separate class. It keeps test scripts clean, avoids duplication, and makes maintenance easier.
In data-driven testing, the same test script is run multiple times with different sets of input data. The test data can be stored in files like Excel, CSV, or databases.
A hybrid framework combines multiple frameworks, for example, keyword-driven and data-driven. This gives flexibility to handle different testing needs.
A framework provides a structured way of writing and organizing test scripts, including rules and best practices. A library is simply a collection of reusable methods or functions that can be used within a framework.
Selenium test cases can be integrated with Jenkins to run automatically. This is useful for continuous integration, where tests are executed whenever new code is added to the project.
Maven manages project dependencies and builds. By using Maven, we can easily add Selenium and other required libraries and run test cases as part of the build process.
AJAX updates parts of a page without reloading it. To handle this, Selenium uses waits that pause execution until the updated element or condition becomes available.
Selenium is mainly for web UI testing, not for APIs. However, for API testing, tools like Rest Assured or Postman are more suitable. Selenium and API tests can still be integrated in one test framework for end-to-end validation.
Selenium provides a way to interact with the browser’s JavaScript engine. This helps when certain elements or actions cannot be handled directly by normal Selenium methods.
Logs are managed by using logging frameworks like Log4j or built-in logging features. Logs help track what actions were performed and where a test failed.
Captchas are designed to prevent automation, so Selenium cannot solve them directly. In testing, developers often disable captchas in test environments, or third-party services are used to bypass them.
In automation frameworks, you may need to verify data in the database. This can be done by connecting to the database from your test code, executing queries, and comparing results with what appears on the application.
Headless browsers are browsers without a visible user interface. They are faster and are used in environments like servers where no screen is available. Tests can be configured to run in headless mode to save time.
In modern development, tests are automated as part of continuous integration pipelines. Selenium can be integrated with tools like Jenkins, GitHub Actions, or GitLab CI so that every time code is updated, tests run automatically to check stability.