Selenium Interview Questions with Answers - 2

11. What are the different exceptions in Selenium WebDriver?

Here are some of the most common exceptions in Selenium Webdriver:

TimeoutException - This is thrown when a command performing an operation doesn't complete in enough time

NoSuchElementException - This is thrown when Webdriver is unable to identify the elements during runtime

ElementNotVisibleException - This is thrown when the element is present in DOM but not visible on the web page

StaleElementException - This is thrown when the element is no longer present on the DOM page

12. How to Handle Exceptions in Selenium Webdriver?

To handle exceptions, a try/catch block is placed around the code that might generate an exception.

13. What is exception test in Selenium?

An exception test refers an exception that we expect will be thrown inside a test class. We use the @Test annotation that specifies which exception will be expecting by mentioning it in the parameters

Example

@Test(expectedException = ElementNotVisibleException.class)

14. What is POM (Page Object Model)? What are its advantages?

Page Object Model is a design pattern for creating an Object Repository for web UI elements. In the Page Object Model Design Pattern, each web page is represented as a class. All the objects related to a particular page of a web application are stored in a class.

Page Object Model is widely used design pattern in Selenium for enhancing test maintenance and reducing code duplication.

Here are few Advantages:

i. We can achieve code reusability using POM by writing the code once and use it for different tests later.

ii. POM makes the clear difference between the test code and page specific code like locators and the layout.  This approach makes the maintenance of code easy.

iii. POM improves the overall readability of the code by separating page specific code with the test code.

15. What is Page Factory?

Page factory is the way to implement page object models. It is class provided to support the Page Object design pattern. It enables to initialize web elements you want to interact within the page object when you create an instance of it.

16. Difference between Page Object Model(POM) and Page Factory?

Page Object is a class that represents a web page and holds the functionality and members.

Page Factory is a way to initialize the web elements you want to interact within the page object when you create an instance of it.

17. What are the advantages of Page Object Model?

i. Code reusability

ii. Code Maintainability

iii. Object Repository

iv. Readability

18. What are the types of frameworks in Selenium?

There are mainly three types of frameworks created by Selenium WebDriver to automate manual test cases:

Data Driven Test Framework

A data driven framework is one in which the test data is put in external files like csv, excel etc. separated from test logic. In this framework, input values are read from data files such as xls, XML, csv, and databases and are stored into a variable in test scripts.

Keyword Driven Test Framework

A keyword driven framework is one in which the actions are associated with keywords and kept in external files e.g. an action of launching a browser will be associated with keyword - launchBrowser()

Hybrid Test Framework

The hybrid framework is a mix of keyword driven and data driven framework.

19. Which files can be used as data source for different frameworks?

Some of the file types of the dataset can be: excel, xml, text, csv, etc.

20. How to set the size of browser window using Selenium?

To maximize the size of browser window, you can use the following piece of code:

driver.manage().window().maximize(); - To maximize the window

To resize the current window to a particular dimension, you can use the setSize() method.