Selenium Interview Questions with Answers - 3
21. How to take a screenshot in Selenium?
There are some of the scenarios we may need to capture screenshot using Selenium WebDriver such as
i. Application issues
ii. Assertion Failure
iii. Difficulty to find Web elements on the web page
iv. Timeout to find Web elements on the web page
Syntax to capture and save the screendshot:
File screenshotFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.File);22. How to work with Excel files in Selenium?
Apache POI is widely used library in the industry to work with excel files in selenium.
We can also use 'JXL' to work with excel files in Selenium.23. What is Apache POI?
Apache POI is an open source library written in Java. It is developed and distributed by Apache Software Foundation to design or modify Microsoft Office files.
This is the most common API used for Selenium data driven tests. Selenium does not support read and write operations on excel files. It uses third party APIs like Apache POI to read and write operations on excel files.24. What is the difference between findElement and findElements?
findElement method is used to access a single web element on a page. It returns the first matching element.
findElements method returns the list of all matching elements.25. List out different types of locators?
A Locator in Selenium is used to find and match the elements of your page that it needs to interact with.
Different types of locators are
ID - Select The Element
Name - Select The Matching Element
Link Text - Select The Link Element
Partial Link Text - Select Link Element
Tag Name - Find The Element
CSS Class Name - Access The Elements
CSS Selector - Access The Elements
XPath - Locate Elements26. What is Selenese and what are the types of Selenese?
Selenese is a set of selenium commands which are used to test web application.
Selenium commands are classified into 3 basic categories.
Actions: These commands change the state of the application like click on some link, select from options, select a value from drop down etc.
Assertions: It is used as a check points. It verifies the state of an application and compares against the expected.
Accessors: These commands check the state of the application and store the application state in some variable.27. Why Selenium RC is used?
Selenium IDE supports only HTML language. Thus, it doesn't support many functions like condition statements, Iteration, unexpected error handling etc.
To handle such issues Selenium RC is used. Selenium-RC offers APIs and libraries for all its supported languages such as Java, C#, HTML, Perl, Ruby, PHP, and Python.h2>28. What is selenium Grid?
Selenium Grid is an important tool of Selenium suite. It allows running tests on different machines against different browsers. It also reduces the time taken by the test suite to complete a test by running tests in parallel.29. What are some advantages of selenium grid?
The advantages of selenium grid are:
i. Selenium grid allows executing multiple test cases on different browsers and operating systems. This way tests can be executed in parallel and thereby saving test execution time
ii. It allows performing cross browser testing.
iii. It allows performing multiple OS testing.
iv. When a node is free, it automatically picks up the test case waiting in the execution queue30. What is testNG? What are some advantages of testNG?
The NG stands for Next Generation. TestNG is an automation testing framework that can be integrated with selenium or any other automation tool to provide multiple capabilities like assertions, reporting, parallel test execution etc.
Following are the advantages of TestNG:
i. With TestNG, it is possible to produce HTML Reports of execution
ii. It allows parallel execution of test cases.
iii. TestNG Annotations made testers life easy
iv. It enables to Group and Prioritize Test Cases more easily.
v. Generation of Log is made possible.
vi. Data Parameterization is possible that allows support for parameterizing Test Cases using @Parameters annotation.