You are on page 1of 12

Selenium With C#

SESSION -02

GET Control - Method

Control methods
string GetAttribute(string attributeName)

Gets the value of the specified attribute for this element.

The attribute's current value. Returns a null if the value is not set.

public IList<IWebElement> AllSelectedOptions { get; }

Gets all of the selected options within the select element.

SingleOrDefault<TSource>(this IEnumerable<TSource> source)

Returns the only element of a sequence, or a default value if the


sequence isempty; this method throws an exception if there is more
than one element in the sequence.

DriverManager Class

Create a separate class to initialize IWebDriver . We do not need to


initialize driver in every place.

Page Object Model (POM)

Reduce Number of duplicate code which does same operation.

Maintain object in separate class file

Improves readability of code

Will have to handle each page using its instance

Establish relation between each page directly in code.

In order to support POM pattern , Web Driver Support library class


called PageFactory

Project using POM

Creating Page Object class

Creating object for page UI

Initialize PageFactory

We have hardcoded the values in the test execution class. In case the
control in HTML changes we need to change the respective element
name.

Add class HTMLPageObject (POM)

Page Object Model

Page Object Modelis a design pattern to createObject


Repositoryfor web UI elements.

Under this model, for each web page in the application there should be
corresponding page class.

This Page class will find the WebElements of that web page and also
contains Page methods which perform operations on those
WebElements.

Name of these methods should be given as per the task they are.

What is Page Factory

Page Factory is an inbuilt page object model concept for Selenium


WebDriver but it is very optimized.

Here as well we follow the concept of separation of Page Object


repository and Test methods. Additionally with the help of PageFactory
class we use annotations@FindByto find WebElement. We use
initElements method to initialize web elements

HTMLPageObject - How to implement POM

PageFactory pattern

PageFactory usage

Normal Factory Pattern

You might also like