16 min read

Top 30 Selenium Interview Questions

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 Tools of choice. Consequently, Selenium related jobs have emerged as coveted spots within the tech industry & by emphasizing 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 a more detailed understanding of the topic, check out our blog on What is Selenium?

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

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 purposes 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.
Selenium Tool Suite

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
Advantages of Selenium

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 then, 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 Same-Origin Policy prohibited access to web elements from a domain which was different from the one where the JavaScript was launched. In other words, the Same-Origin Policy implied that a web browser allowed scripts from a particular webpage to access content of another webpage provided both the pages came from the same domain.

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.

Functional Testing
  • 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.
Regression Testing

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 (/)
  1. It helps in starting the selection from the document or the start node
  2. It allows the user to create Absolute expressions in XPath Selenium
  • Double Slash (//)
  1. It helps in starting the selection from anywhere in the document
  2. It allows the user to create Relative expressions in XPath Selenium
syntax of xpath

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.

  • Name
  • ID
  • Partial Link
  • Class
  • XPath
  • 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.

Advantages:

  • 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:

  • Test
  • Before
  • After
  • BeforeClass
  • AfterClass
  • Ignore
  • RunWith

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 programs 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.

Captcha

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.
automation testing 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 while 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?

Advantages:

  • 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

Disadvantages

  • 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

selenium

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 function 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.

If you wish to know more about this part of the Selenium suite; check out our blog on “What is Selenium Grid?

selenium grid

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?

Limitations:

  • 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

limitations of Selenium WebDriver

26. What are the challenges in handling Ajax call in Selenium WebDriver?

Challenges:

  • 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 neither 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?

These are:

  • 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.
waits in Selenium

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
  1. 200- Valid Link
  2. 404- Link Not Found
  3. 400- Bad Request
  4. 401- Unauthorized
  5. 500- Internal Error

You can repeat the process for all the links gathered

Conclusion

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.

Articles you may like:

Selenium Tester: Roles, Jobs, Resume, Salary

Selenium Tester: A Role to Look Forward To

Top 25 Selenium Tricky Interview Questions

SDET automation certification course

Like what you read?
Share with your community!

Subscribe to our
newsletter