Selenium is an open-source tool used for automation testing, which allows you to test web applications across a range of browsers. It was introduced once manual testing started to pose several challenges, and there was a high demand for a method that automates the testing process. This Selenium Java interview questions blog has a compiled list of most of the questions that are asked during Selenium job interviews. The most-asked Selenium interview questions for experienced and freshers are mentioned below:
Q1. What is automation testing?
Q2. Is Selenium 2.0 different from Selenium 3.0? If so, how?
Q3. Mention some of the popular tools used for automation testing.
Q4. What is a locator? How will you locate an element in Selenium?
Q5. What are the test types supported by Selenium?
Q6. What is XPath?
Q7. Explain the difference between single slash and double slash in XPath.
Q8. Why should you use Selenium for test automation?
Q9. Does Selenium have any technical limitations? If so, what are those limitations?
Q10. What is an object repository?
Below are the three major parts that this Selenium interview questions blog is divided into:
1. Basic Interview Questions
2. Intermediate Interview Questions
3. Advanced Interview Questions
Watch this video on Selenium Interview Questions and Answers:
Basic Selenium Interview Questions for Freshers
1. What is automation testing?
Automation testing is the process of automating the manual testing of the application under test (AUT) or the system under test (SUT). It includes the involvement of testing tools that help us create test scripts, which can be used repeatedly without any human intervention.
2. Is Selenium 2.0 different from Selenium 3.0? If so, how?
Selenium RC is called Selenium 2.0, and the integration of Selenium RC and WebDriver as a single tool has formed Selenium 3.0.
3. Mention some of the popular tools used for automation testing.
- Rational Robot
- HP Unified Functional Testing (UFT)
- IBM Rational Functional Tester
4. What is a locator? How can you find elements in Selenium?
Selenium uses locators to find and match the elements of a web page that it needs to interact with. There are different types of Selenium locators to identify various web elements on a web page:
- Partial Link
- CSS Selector
- Link Text
5. What are the test types supported by Selenium?
For testing web-based applications, Selenium can be used.
The test types supported by Selenium are:
- Functional testing: It verifies if each function of a software application performs in accordance with specific requirements. This testing primarily involves black-box testing, and it is not concerned about the source code of the application.
- Regression testing: It is nothing but a full or partial selection of the already executed test cases to be re-executed to ensure whether the existing functionalities work fine.
Learn more about Selenium from this insightful blog on How would you test Web Applications using Selenium?
Get 50% Hike!
Master Most in Demand Skills Now !
6. What is XPath?
While DOM is the recognized standard way for navigating through an HTML element tree, XPath is the navigation tool used to locate a web element based on its XML path.
XML stands for ‘Extensible Markup Language’ and is used to store, organize, and transport arbitrary data. It stores data in a key–value pair that is very much similar to HTML tags. Both being markup languages and falling under the same umbrella, XPath can be used to locate HTML elements.
The fundamental concept behind locating elements using XPath is traversing between various elements across the entire page and thus enabling a user to find an element with the reference of another element.
7. Explain the difference between single slash and double slash in XPath.
- Single slash (/): Single slash is used to create an XPath with an absolute path. In this case, the XPath would start selection from the document’s start node.
- Double slash (//): Double slash is used to create an XPath with a relative path. In this case, the XPath would start selection from anywhere within the document.
8. Why should you use Selenium for test automation?
Selenium should be used for test automation as it:
- Is a free and open-source tool
- Has a large user base and community support
- Has cross-browser compatibility (Firefox, Chrome, Internet Explorer, Safari, etc.)
- Has great platform compatibility (Windows, Mac OS, Linux, etc.)
- Supports multiple programming languages (Java, C#, Ruby, Python, Perl, etc.)
- Has fresh and regular repository developments
- Supports distributed testing
9. Does Selenium have any technical limitations? If so, what are those limitations?
Yes, Selenium has a few limitations:
- Testing of only web applications is possible using Selenium.
- Testing of mobile applications or desktop applications is not possible.
- Captcha and barcode readers cannot be tested using Selenium.
- A third-party tool like TestNG or JUnit should be used to generate reports.
- As Selenium is a free tool, there is no ready vendor support through which users can find various helping communities.
- Prior programming language knowledge is expected from users.
Enroll today in our Selenium Course to know more about Selenium!
10. What is an object repository?
An object repository allows testers to accumulate web elements of the application under test (AUT), along with their locator values, in one or more centralized locations as restricted to hard-coding them within the test scripts.
11. What is the difference between type keys and type commands?
12. What are the advantages of Selenium?
- Selenium is a purely open-source and portable automation testing tool.
- It supports different languages such as C#, PHP, Java, Perl, Python, JS, and Groovy.
- It also supports different OS, including Windows, Linux, UNIX, and Mac OS.
- It provides powerful methods such as Xpath, DOM, and CSS to locate elements.
- Since it is an open-source tool, developers can customize the code. Also, the developer community is supported by Google.
Watch this video on Selenium automation testing tutorial:
13. Define automation testing, and list down its advantages.
Automation testing or test automation is the process of automating the testing process by using tools to write and execute test cases without any human intervention. It allows us to create scripts that can be executed frequently and generate detailed test reports of the application.
Its advantages are as given below:
- It helps in the performance and functional testing of an application.
- It makes the execution of repeated test cases easy.
- It supports the parallel execution of multiple test cases.
- It boosts the accuracy and efficiency of the application by cutting down the chances of human error.
- It easily performs testing on a large-scale test matrix.
- It saves time and money by reducing the burden of arbitrary tasks.
14. What are the significant changes/upgrades made to various Selenium versions?
Selenium’s first version included only three sets of tools: Selenium IDE, Selenium RC, and Selenium Grid. There was no WebDriver included in the first version. Later, Selenium WebDriver was introduced and hence included in Selenium V2. However, as WebDriver got included, the use of Selenium RC was discouraged with time and is not much in use ever since. Selenium 3 is in use, and it has newly added features such as IDE and WebDriver. Selenium 4 is the latest released version.
15. How many types of WebDriver APIs are available in Selenium?
The following is the list of WebDriver APIs:
16. What is an exception test in Selenium?
An exception test is a test that looks forward to an exception to be thrown inside a test class. It anticipates the @Test annotation followed by the expected exception name. For example, @Test(expectedException = NoSuchElementException.class) is an exception test for missing elements in Selenium.
Note: Keep in mind the syntax, where the exception is suffixed with .class.
17. What is POM (Page Object Model)? What are its advantages?
Page Object Model is a design pattern used to create object repositories for the web UI elements. Every web page of an application has a corresponding page class that is responsible for locating the web elements and performing actions on them.
Its advantages are as follows:
- It provides support to separate operations and flows on the UI from verification, hence improving code readability.
- As the object repository is independent of test cases, multiple tests can use the same object repository.
- It increases the reusability of the code
That’s all for the basic Selenium Java interview questions. Let’s move on to the next section of intermediate Selenium WebDriver interview questions.
Intermediate Selenium Interview Questions and Answers
18. What are the different types of annotations used in Selenium? Explain the JUnit annotation linked with Selenium.
In Java, a special form of syntactic metadata can be added to Java source code, which is known as ‘annotations’. Variables, parameters, packages, methods, and classes are annotated. Some of the JUnit annotations are:
JUnit annotations linked with Selenium are:
JUnit AnnotationsJUnit Annotations
- @Test: The @Test annotation finds a method to be a test method. When used before a test method, it is mentioned as ‘@Test’; it informs the JUnit framework that the following method is a test method.
- @Before: The @Before annotation is used to find the method that is executed before executing the test method. This method can be used to set up the test environment.
- @After: The @After annotation is a method that is executed after executing the test method. This method can be used to do a teardown, i.e., it is a method used to delete all temporary data, set up default values, clean up the test environment, etc.
- @BeforeClass: The @BeforeClass method is used only once before the start of all tests. Basically, this is used to perform cumbersome activities, like connecting to a database.
- @AfterClass: The @AfterClass method is used only once after executing all tests. This is used to carry out clean-up activities, like disconnecting from a database.
19. Why do testers choose Selenium over QTP?
Selenium is more widely used than QTP since:
- Selenium is an open-source tool, whereas QTP is a profitable tool
- Selenium is used specifically for testing web-based applications, while QTP can be used for testing client–server applications too
- Selenium supports multiple browsers like Firefox, IE, Opera, Safari, etc. and has multiple operating systems compatibility too. Selenium-supported OS platforms are Windows, Mac, Linux, etc. On the other hand, QTP is limited to Internet Explorer on Windows
- Selenium supports multi-programming language compatibility. Languages supported by Selenium are Python, Ruby, Perl, etc. But, QTP supports only VBScript
You can find more on Selenium by visiting our Selenium Community!
Watch this video on Selenium automation testing tutorial:
20. What are the four elements that you have to pass in Selenium?
Four parameters that need to be passed in Selenium are:
- Port number
21. What is Same-origin Policy? How can we avoid it?
The ‘Same-origin Policy’ is introduced for security reasons.
- It ensures that the content of our site will never be accessible by a script from another site.
- As per the policy, any code loaded within the browser can only operate within that website’s domain.
To avoid this same-origin policy, the proxy injection method is used. In the proxy injection mode, Selenium Server tricks the browser to be a real HTTP URL, i.e., it acts as a client-configured HTTP proxy, which sits between the browser and the application under test (AUT) and then masks the AUT under a fictional URL.
22. What are data-driven framework and keyword-driven framework?
A data-driven framework in Selenium is an approach of separating a ‘dataset’ from the actual ‘test case’ (code). This framework is completely dependent on the input test data. The test data is inserted from external sources, such as from an Excel file, a CSV file, or from any database. It also allows us to easily control how much data needs to be tested. We can easily increase the number of test parameters by adding more username and password fields to the Excel file (or other sources).
A keyword-driven framework is an extension to the data-driven testing framework in the sense that it not only isolates the test data from the scripts but also keeps the particular section of the code belonging to the test script in an external data file. These sets of code are known as keywords, and hence the framework is so named. Keywords are self-guiding and work based on what actions need to be performed on the application.
23. How will you use Selenium to upload a file?
If the file is on the same machine or in a mapped network drive, it is really straightforward: We have to just type the ‘path’ of the file in the FileUpload control.
driver = webdriver.Firefox()
element = driver.find_element_by_id("fileUpload")
Learn more about Selenium from this informative Selenium Tutorial!
24. What is the difference between getwindowhandles() and getwindowhandle()?
- getwindowhandles(): It is used to get the address of all open browsers, and its return data type is Set<String>.
- getwindowhandle(): It is used to get the address of the current browser where the control is, and its return type is a string data type.
25. What is Selenese, and what are the three types of Selenese?
Selenese is a set of commands in Selenium used for running a test.
Three types of Selenese are as follows:
- Actions: They are used for performing interactions and operations with the target elements.
- Accessors: They are used for storing values in a variable.
- Assertions: They are used as a checkpoint.
26. If you want to insert a breakpoint in Selenium IDE, how can you do that?
To insert a breakpoint:
- First, select ‘Toggle Breakpoint’ by right-clicking on the command in Selenium IDE
- Then, press ‘B’ on the keyboard and select the command
- The same step should be repeated for deselecting a breakpoint
27. How do you launch the web browser using WebDriver?
The following syntax can be used to launch the browser corresponding to the system’s operating system:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new InternetExplorerDriver();
WebDriver driver = new ChromeDriver();
28. List down some of the technical challenges with Selenium.
- Testing a Windows application: Selenium is just a web-based driver. It does not support Windows-based apps and only supports web apps.
- Testing mobile apps: With the help of Selenium, we can test web apps on any OS and browser that run on desktops. But, we cannot test mobile apps with Selenium because it does not work with OS such as Android and iOS. However, there is an alternative for this, i.e., Appium. It is an open-source automation testing tool that uses the WebDriver protocol to drive native, hybrid, and iOS and Android, which is built specifically for testing mobile apps.
- Limited reporting: It is one of the key challenges. In Selenium, we cannot generate efficient and accurate reports. Accurate reports help developers fix all bugs and errors. We can create reports using TestNG or ExtentReports.
- Handling dynamic elements: With the surge in the use of web apps, the management of dynamic elements should be as much efficient as possible. When a web page loads, the content present on the page changes depending on the user, location, and other factors. Most of today’s web apps are dynamic in nature for better user experience, e.g., e-commerce websites. In Selenium automation, the handling of dynamic web content is a major challenge. However, Selenium provides an explicit wait feature, where we can set a time interval for the automation testing process to hold the process for the new content to load. Also, another alternative is to utilize the implicit wait feature.
- Handling page load: Some of the web pages in a web app are user-specific. They load elements depending on the user. Also, some elements may be loaded depending on the user’s previous activities. During background processes, the Selenium script might not be able to identify a specific element. To overcome this, we can use explicit waits to provide sufficient time to load and discover the element.
- Handling pop-up windows: Whenever any simple, prompt, or confirmation alert pops up, it is difficult to automate it. Windows-based OS alerts are beyond Selenium’s capabilities as they are part of the OS instead of the browser. However, Selenium WebDriver can utilize multiple windows, and the web-based alerts can easily be handled with the help of the switchTo method. It manages the OS-based pop-ups while keeping the browser running in the background.
29. What is the difference between setSpeed() and sleep() methods?
Both setSpeed() and Sleep() in Selenium are used to delay the speed of execution.
- setSpeed: Sets the execution speed with a delay of milliseconds, followed by the Selenium operation. By default, the delay is 0 milliseconds.
- sleep: Causes the suspension of execution of the current thread for a specified period.
That is all in the section of intermediate Selenium framework interview questions. Let’s move on to the next section of Selenium advanced interview questions.
Advanced Selenium Interview Questions for Experienced Professional
30. What are the different types of waits available in WebDriver?
There are two types of waits available in WebDriver:
- Implicit wait: These waits are used to provide a default waiting time (say, 30 seconds) between the consecutive test steps across the entire test script. Hence, the subsequent test step would only be executed when the 30 seconds are over after executing the previous test step.
- Explicit wait: These waits are used to halt the execution until a particular condition is met or the maximum time has elapsed.
Explicit waits are instantiated for a particular instance only, whereas implicit waits are not.
31. How do you handle a frame in WebDriver?
An iframe (an acronym for ‘inline frame’) is used to insert another document within the current HTML document.
Selecting iframe by ID:
driver.switchTo().frame(“ID of the frame“);
Locating iframe using the tagName:
Locating iframe using index:
- frame(“Name of the Frame”)
driver.switchTo().frame(“name of the frame”);
- frame(WebElement element)
Select Parent Window
Go through the Selenium Course in London to get a clear understanding of Selenium!
32. How do you set the test case priority in TestNG?
Setting Priority in TestNG:
Test Execution Sequence:
33. What are the different types of frameworks?
Different types of frameworks are as follows:
- Module-based testing framework: This framework divides the entire application under test (AUT) into a number of logical and isolated modules. For each module, we create a separate and independent test script. Thus, when these test scripts are taken together, it builds a larger test script representing more than one module.
- Library architecture testing framework: Instead of dividing AUT into test scripts, with this framework, we segregate the application into functions or rather common functions that can be used by the other parts of the application as well. Thus, we create a common library constituting common functions for AUT. Therefore, these libraries can be called from the test scripts whenever required.
- Data-driven testing framework: The data-driven testing framework helps us segregate the test script logic and the test data from each other. It lets us store the test data into an external database. The data is conventionally stored in ‘key–value’ pairs. Keys can be used to access and populate the data within the test scripts.
- Keyword-driven testing framework: The keyword-driven testing framework is an extension to the data-driven testing framework in the sense that it not only segregates the test data from the scripts but also keeps a certain set of codes belonging to the test script in an external data file.
- Hybrid testing framework: A hybrid testing framework is a combination of more than one of the above-mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.
- Behavior-driven development framework: The behavior-driven development framework allows the automation of functional validations in an easily readable and understandable format for Business Analysts, Developers, Testers, etc.
34. Describe the difference between Selenium and QTP.
||Quick Test Professional (QTP)
||It supports almost all popular browsers: Firefox, Chrome, Safari, Internet Explorer, Opera, etc.
||QTP supports Internet Explorer, Firefox, and Chrome. It only supports Windows operating system
||It is distributed as an open-source tool and is freely available
||It is distributed as a licensed tool and is commercialized
|Application under test (AUT)
||It supports the testing of web-based applications only
||It supports the testing of both web-based and Windows-based applications
||Object repository needs to be created as a separate entity in Selenium
||QTP automatically creates and maintains the object repository
||It supports multiple programming languages like Java, C#, Ruby, Python, Perl, etc.
||It supports only VBScript
||As Selenium is a free tool, users would not get the vendor’s support in troubleshooting issues
||Users can easily get the vendor’s support if they face any issues
Learn more about Selenium in this Selenium Training in New York to get ahead in your career!
35. In Selenium, what are breakpoints and start points?
Breakpoints: Breakpoints are used to stall the execution of the test. The execution will stop whenever a breakpoint is implemented, and this will help us check whether the code is working properly or not.
Start points: Start points are the points from where the execution should begin. Start points can be used when we want to run the test script from the middle of the code or after a breakpoint.
36. Mention the need for session handling while working with Selenium.
While working with Selenium, we need session handling. This is because, during test execution, Selenium WebDriver has to interact with the browser all the time to execute the given commands. It is also possible that, before the current execution completes, someone else starts the execution of another script in the same machine and in the same type of browser. So, to avoid such a situation, we need session handling.
37. Mention the types of listeners in TestNG.
The types of listeners in TestNG are:
38. How can we handle Windows-based popups with Selenium?
Selenium solely supports web application testing. It does not support the testing of Windows-based applications or mobile applications. To handle Windows-based popups, third-party intervention is required. AutoIt and Robot Class are examples of third-party tools that we can use alongside Selenium to handle Windows-based popups.
Interested in learning Selenium? Check out our Selenium Training in Sydney!
39. For the database testing in Selenium WebDriver, what API is required?
For the database testing in Selenium WebDriver, we need the JDBC (Java Database Connectivity) API. It allows us to execute SQL statements.
40. How can you identify an object in Selenium?
We can use isElementPresent (string locator) to find an object in Selenium. It takes a locator as the argument and, if found, returns a Boolean.
Become a master of Selenium by taking up this online Selenium Course in Toronto!
41. Mention the use of XPath in Selenium testing.
XPath is used to define web elements on a web page. The major advantage of XPath is that it helps us in identifying the elements dynamically.
There are two types of XPath:
- Absolute XPath
- Relative XPath
42. What is Selenium?
Selenium is a popular open-source software that is used to automate web-based applications. It is a set of multiple software tools, and each tool has a different approach to automated testing.
Selenium has four major components, namely:
- Selenium Integrated Development Environment
- Selenium Remote Control
- Selenium WebDriver
- Selenium Grid
43. Can WebDriver test mobile applications?
No, WebDriver is a testing tool used for web-based applications. So, we cannot test mobile applications with Selenium WebDriver.
44. Explain how Selenium Grid works.
Selenium Grid creates a test suite that works by forwarding test cases to the hub, and from there, the test cases are redirected to Selenium WebDriver. WebDriver will then execute them in the browser. The test suite allows for running tests in parallel.
Hope you find our comprehensive blog on Selenium testing interview questions useful. Do let us know in the comments section if you could make use of these Selenium topics for interview.
45. Explain the difference between driver.close() and driver.quit() commands in Selenium.
The following is the major difference between both commands:
- close() command closes the currently active browser window, which is being used by the user or which is currently accessed by the web driver.
- quit() command closes all the windows opened by the program, unlike the driver.close () command.
Both the commands do not take any value and also do not accept any parameter.
46. Explain the difference between findElement() and findElements() in Selenium.
The difference between findElement() and findElements() is as follows:
- findElement(): It finds one particular element within the current page using the locating mechanism. It returns the first element located by the locator.
- findElements(): It finds all the elements within the current page with the help of the locating mechanism. Hence, it returns a list of matching web elements found by the locator.
47. Mention the types of navigation commands.
The following are the navigation commands provided by Selenium:
- navigate().back(): It takes the user back to the previous or the last-used web page, according to the history.
- navigate().forward(): It takes the user to the next web page, according to the browser history.
- navigate().refresh(): It allows the user to refresh the current web page by reloading all the web elements.
- navigate().to(): It takes the user to a new web page in a new window, depending on the URL specified.
48. How do you find broken links in Selenium WebDriver?
We can detect whether the given links are broken or not by using the following process:
- First, accumulate all the links present on a web page using the <a> anchor tag. For each <a> tag, use the attribute ‘href’ value to obtain the hyperlink
- Send HTTP requests for each link and verify the HTTP response code
- Based on the HTTP response code, determine if the link is valid or broken. Then, use the driver.get() method to navigate to a URL, which will respond with a status of 200 – OK (200 – OK indicates that the link is working). If we get any other status, then it indicates that the link is broken
- Repeat the same process for all the links captured