Software testing as one of the crucial phases of the software development lifecycle ensures the release of bug-free software in the market which would be able to meet the needs of the customers.
Testing can be undertaken in a manual as well as in an automated fashion. While there are a number of Test Automation Tools available, Selenium has emerged as one of the foremost Testing Tool of choice. Consequently, Selenium related jobs have emerged as coveted spots within the tech industry & by emphasising upon some of the most significant Selenium Interview Questions, this guide will help you ace a Selenium Interview like a pro. This blog has been carefully curated as a helpful guide covering some of the most important Selenium Interview Questions which appear in interviews across companies. This list of Selenium Interview Question and Answers focus on some of the most important areas that you must pay attention to as you prepare for your interview.
➡ For the purpose of convenience, this blog has been divided into four parts and covers the top 30 Selenium Interview Questions and Answers.
- Interview Questions on Selenium: BASIC Level
- Selenium Interview Questions: INTERMEDIATE Level
- Selenium Interview Questions for Experienced: ADVANCED Level
- Selenium WebDriver Interview Questions
Interview Questions on Selenium: BASIC Level
1. What are the different Selenium Suite Components?
The Selenium Automation software is not a single tool, but a suite of software, each of which serves a specific set of testing purpose for the organization. The tools are:
- Selenium Integrated Development Environment (Selenium IDE): It works as a Firefox plug-in which can be used to record and execute test cases. It was primarily created to accelerate the production of automation scripts
- Selenium Remote Control (Selenium RC): It was the first flagship testing tool which allowed users to write test cases in the preferred language of the user. It provides for cross-browser testing as well as data-driven testing.
- Selenium WebDriver: It was created by Simon Stewart in 2006, as a solution to the shortcomings of Selenium RC. It provides an interface for creation as well as execution of test cases and it is possible to identify web page elements through the test cases and take appropriate action.
- Selenium Grid: It makes use of the Hub-Node design which helps in simultaneous execution of more than one test case on different machines which happen to be remotely located. There is one master system which is the hub and it controls the other child systems which are the nodes. Thus, it provides for parallel execution.
2. Why should you use Selenium? What are its advantages?
- Open-source and free
- Supports test scripts in different programming languages
- Provides for execution of test cases on multiple browsers and more than one operating systems
- Facilitates parallel testing and has a huge community support
- Provides for integration with JUnit and TestNG
- Allows for Continuous Testing through integration of Selenium with Maven, Jenkins and Docker
3. What is the difference between Selenium 2.0 and Selenium 3.0?
Selenium 2.0 provided for the merger of the Selenium Webdriver project with the original Selenium Project. Ever since so, Selenium RC got disapproved of, but was still used for backward compatibility.
Selenium 3.0 is held to be the extended version of Selenium 2.0. It is backward compatible, does not include Selenium RC and is inherently stable with several bug fixes.
4. What is Selenese? What are its types?
Selenese refers to Selenium commands which act as instructions for executing the test cases. A test script can be seen as a sequential collection of these Selenese commands.
There are three types of Selenese:
- Actions: These commands are used for conducting operations on and interacting directly with the target elements.
- Accessors: This command helps in storing values in a variable.
- Assertions: These commands act as checkpoints for keeping track of the sequential execution of commands.
5. What is the Same-Origin Policy? How was it resolved?
The problem posed by the same-origin policy was sought to be rectified through the introduction of Selenium RC. It did seek to resolve the issue by including a HTTP proxy server which could deceive the browser into believing that the web application and the test script came from the same source. Thus, the issue of the same-origin policy is handled through the proxy injection method.
6. What are the different test types supported by Selenium?
The different test types supported by Selenium are:
- Functional Testing: This kind of testing is conducted in order to determine whether an application functions as per the requirements of the project. Generally, it involves black box testing and does not concern itself with the source of the code.
- Regression Testing: It involves selection (full or partial) of already executed test cases in order to get them re-executed for evaluating the performance of existing functionalities.
7. What is the difference between Verify and Assert Commands?
- Verify: This command is used to check whether an element is on a page. It is used to specify whether a condition is true or false. If the element is not there, the test will keep on executing. Even if any of test fails, the rest of the commands will continue to run.
- Assert: This command is used to check whether an element is on the page or not. If the asserted element is not present, then the test will stop and will not continue further. Thus, the test terminates at the point where the check fails.
8. What is the difference between single slash and double slash in XPath in Selenium?
- Single Slash (/)
- It helps in starting the selection from the document or the start node
- It allows the user to create Absolute expressions in XPath Selenium
- Double Slash (//)
- It helps in starting the selection from anywhere in the document
- It allows the user to create Relative expressions in XPath Selenium
9. What is a locator? How will you locate an element in Selenium?
Locators in Selenium act as means for finding and matching elements on a webpage with which the user needs to interact with. Depending on the type of element which needs to be located, there are different types of locators present.
- Partial Link
- Link Text
- CSS Selector
10. What are the technical limitations of Selenium?
- It can only be used to test web applications and is not suitable for testing mobile or desktop software applications
- It cannot acquire access to web elements detected to be outside the web application which is under test
- There is no assured user support, apart from customer communities
- It cannot be used for image testing or data-driven testing independently
- It requires prior knowledge of programming language to write tests
- Selenium cannot be used to test Captcha and barcode readers
11. What is the Page Object Model (POM)? What are its advantages?
POM can be understood as a design pattern which helps in creating object repositories for the web UI elements. The web pages of applications have corresponding page classes which help in locating web elements and undertaking actions on them.
- The same object repository can be used in multiple tests, as the repository itself is independent of test cases
- It helps in providing for code readability, as it supports separate flows and operations on the UI from verification
- It also enhances the reusability of the code
Selenium Interview Questions: INTERMEDIATE Level
12. What are the different types of annotations used in Selenium?
Java facilitates the addition of a special form of syntactic metadata to the Java source code, which are known as annotations. It provides for the annotation of parameters, methods, variables, classes and packages. Some of these JUnit annotations are:
13. Can you automate Captcha?
Selenium cannot be used to automate Captcha. This is quite logical because the whole idea behind Captcha is to prevent automated program and bots from acquiring access to sensitive information. Thus, it is immune to automation through Selenium. The Captcha needs to be manually typed by the tester or the test engineer in order to carry on the execution of the test suite.
14. What are the advantages of Selenium over QTP?
- Selenium is distributed as an open-source, free Automation Tool; while QTP is commercialized and is distributed as a licensed, profitable tool
- Selenium supports multiple programming languages; QTP supports only VBScript
- Selenium supports multiple browsers as well as different operating systems; QTP supports only Firefox, Internet Explorer and Chrome, and the Windows operating system
- While Selenium is specifically used for testing web-based applications; QTP can be used for testing client-server applications too
15. What are Breakpoints and Start points in Selenium?
- Breakpoints: These are used to stall the flow of execution of the test cases. When Breakpoint is implemented, the execution stops right there. This also helps in ascertaining that the code is working properly.
- Start points: This refers to the point from where the execution of test suite should begin. This is invoked when the tester wants to execute the test script from the middle of a code or after a breakpoint.
16. What is the difference between setSpeed() and sleep() methods?
Both these methods are used to delay the speed of execution.
- setSpeed(): This command is used to stop the execution of every Selenium command for a specific amount of time. Each command after the setSpeed delay is executed with a delay of milliseconds as mentioned in setSpeed. It is used in case of a slow web application or for demonstration purposes.
- Thread.sleep(): This command suspends the execution of the current thread for a specified amount of time. It can be invoked only once. It takes a single argument in integer format.
17. What is the difference between getwindowhandles() and getwindowhandle()?
- getwindowhandles(): It is used to get the address of all the open browser and its return 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.
18. What are the different types of frameworks?
The different types of frameworks are:
- Data-Driven Testing Framework: This framework assists us in separating the test data from the test script logic. The test data is stored in an external database like XML, excel, CSV and so on. The data is stored in “key-value” pairs and they depend on the verification and input values maintained using the variables.
- Keyword-Driven Testing Framework: This framework is often considered to be an extension of the previous one. It not only provides for the separation of the test data from the test scripts, but also retains a certain set of codes belonging to the test script in an external data file. The keywords and data tables are developed independently of the automation test cases.
- Behavior Driven Testing Framework: This framework provides for the automation of functional validations in the test script for ensuring understanding, reliability and readability for Business Analysts, Testers and Developers.
- Module-Based Testing Framework: This framework helps in dissociating the Application Under Test (AUT) into isolated and logical modules. Independent and separate test scripts are created for each module and taken together they help in building a larger test script which represents more than one module.
- Library Architecture Testing Framework: This framework helps in segregating the application into common functions which can be used by other parts of the application as well. This helps in creating a common library which constitutes common functions for AUT.
- Hybrid Testing Framework: It is a combination of more than one of the above mentioned frameworks. The advantage is that it helps in deriving the benefits of all the associated frameworks.
Selenium Interview Questions for Experienced: ADVANCED Level
19. How will you launch different browsers in Selenium?
It will require the creation of a driver instance for a particular browser which we need to work upon. The following syntax can then be used to launch the browser corresponding to the operating system of the system.
- WebDriver driver = new ChromeDriver()
- WebDriver driver = new FirefoxDriver()
- WebDriver driver = new InternetExplorerDriver()
In these cases, WebDriver acts as the interface wherein Chrome, Firefox and all other browser driver implementations are made.
20. Why do you need Session Handling in Selenium?
Session handling is crucial while working with Selenium. It helps in establishing the communication between the browser and the application which running the commands. The need for session handling comes from the very fact that during the process of test execution, the WebDriver needs to continuously interact with the browser for executing the commands. There may arise an issue that in the process of running a particular test script and before the current execution gets completed; someone might start the execution of another test script in the same machine with the same type of browser. In order to avoid such a situation, we need Session Handling in Selenium.
21. What are the advantages and disadvantages of Selenium RC?
- It supports cross-browser testing, user preferred language and data driven testing
- Supports conditional operations and iterations as well as new browsers
- The execution speed is greater than Selenium IDE
- Dynamic objects and Ajax based UI elements can be handled
- Data can be read or write to or from .xlsx, .csv, .txt, and so on
- It involves a complicated installation procedure as compared to Selenium IDE
- Prior knowledge of programming language is needed
- Execution speed is slow as compared to Selenium WebDriver
- API contains vague commands
- Anything outside the browser is also restricted to access in the test scenario execution
22. Which language is more preferred for writing test suites in Selenium?
While Selenium does allow the writing of test scripts in multiple languages; the most preferred language is Python over Java.
- Python programs run faster as compared to Java programs
- The complexity and implementation of both are different and Python works quite well
- Java is statically typed, while Python is dynamically typed
- Python is far compact and simpler to write test cases when compared to Java
23. How does Selenium Grid work?
Selenium Grid operates by creating test suites which functions by forwarding test cases to the hub, from where the cases are redirected to the Selenium WebDriver. The WebDriver is then responsible for executing the cases in the browser. The test suite does allow for parallel testing.
24. What are the different navigation commands in Selenium?
The different navigation commands in Selenium are as follows:
- navigate().refresh(): This command helps the user to refresh the current webpage by reloading all the web elements
- navigate().back(): This command operates as a Back Button. It takes the user back to the last used or previous webpage as per the user history
- navigate().to(): This command takes the user to a new page in a new window, depending on the URL mentioned in the command
- navigate().forward(): This command operates as a Forward Button. It takes the user back to the next webpage as per the user history
Selenium Webriver Interview Questions
25. What are the limitations of Selenium WebDriver?
- Selenium WebDriver entails prior knowledge of programming language
- Does not immediately support new browsers and there is no procedure to track runtime messages
- Selenium WebDriver does not allow for image testing
- Not compatible to test mobile or desktop or windows applications
- There is built-in reporting option and it needs to be integrated with other tools in order to obtain the reports
- There is no vendor support since it is open source
26. What are the challenges in handling Ajax call in Selenium WebDriver?
- It is difficult to evaluate the risks associated with particular Ajax applications
- The pause command is one of the options for handling Ajax calls, but it is not completely reliable. Long pause time only results in increasing the testing time and makes the test unacceptably slow. It is recommended that the “waitforcondition” will be more useful in testing Ajax applications
- Serialization and Encoding in the Ajax applications make it difficult in developing automation test scenarios
27. How can you handle colors in Selenium WebDriver?
In order to handle colors in WebDriver, you can use
getCssValue(arg0) function to get the colors by sending ‘color’ string as an argument.
28. What are the different types of Exceptions in Selenium WebDriver?
The different kinds of exceptions in Selenium WebDriver are:
- ElementNotVisibleException: This exception occurs when an element is present in the DOM (Document Object Model), but is not visible on the webpage
- TimeOut Exception: This exception occurs when a particular operation cannot be completed within a stipulated or specified time
- StaleElement Exception: This exception occurs when an element is no longer present or is deleted in the DOM (Document Object Model). Users tend to face this exception when the element that they are interacting with is either recreated or destroyed again
- NoSuchElement Exception: This exception occurs when an element in the given set of attributes is not present in the webpage
29. What are the different types of waits supported by Selenium WebDriver?
- Implicit Wait: These waits are used to set a default waiting time between the consecutive steps across the entire test script. A particular test step will only be executed after the specified time has elapsed, post the execution of the previous step.
- Explicit Wait: These waits are used to halt the execution of a test until the maximum time has elapsed or a particular condition is met.
30. How do you find broken links in Selenium WebDriver?
Detection of broken links can be made in the following manner:
- You need to gather all the links present on a webpage through the <a> anchor tag. For each of the <a> tag, you will be required to use the attribute ‘href’ value to obtain the hyperlink
- Next you would have to send HTTP requests for each link and correspondingly verify the HTTP response code
- On the basis of the HTTP response code, you will be able to determine if the link is broken or valid. Then, you can use the driver.get() method to navigate to a URL which should respond with a 200-OK status if the link is working. In case you get other statuses, it indicates that the link is broken
- 200 – Valid Link
- 404 – Link Not Found
- 400 – Bad Request
- 401 – Unauthorized
- 500 – Internal Error
You can repeat the process for all the links gathered
The list of possible Selenium Interview Questions mentioned above is certainly by no means exhaustive. As an aspiring candidate seeking to get through a Selenium Interview, you might happen to face numerous other Selenium tricky Interview Questions. However, this blog has sought to give you a fair idea of the most important topics which you should certainly be well versed with, when it comes to this Automation Testing Tool.