Selenium Interview Questions
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.
- Selenium
- 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:
- ID
- Name
- Class
- Partial Link
- XPath
- 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. know more at Selenium online training
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.
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?
TypeKeys() will trigger JavaScript events, while type() won’t. TypesKeys collects different value attributes using JavaScript. Whereas, the type commands imitate an actual user typing. know more at Selenium training
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.
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:
- AndroidDriver
- ChromeDriver
- EventFiringWebDriver
- FirefoxDriver
- HTMLUnitDriver
- InternetExplorerDriver
- iPhoneDriver
- iPhoneSimulatorDriver
- RemoteWebDriver
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. know more at Selenium online course
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.
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:
- Test
- Before
- After
- Ignore
- BeforeClass
- AfterClass
- RunWith
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 know more at Selenium online training from india
20. What are the four elements that you have to pass in Selenium?
Four parameters that need to be passed in Selenium are:
- Host
- Port number
- Browser
- URL