PageFactoryInitElementsT Method (IWebDriver)WebDriver
Initializes the elements in the Page Object with the given type.

Namespace: OpenQA.Selenium.Support.PageObjects
Assembly: WebDriver.Support (in WebDriver.Support.dll) Version: 3.1.0
Syntax

public static T InitElements<T>(
	IWebDriver driver
)

Parameters

driver
Type: OpenQA.SeleniumIWebDriver
The IWebDriver instance used to populate the page.

Type Parameters

T
The Type of the Page Object class.

Return Value

Type: T
An instance of the Page Object class with the elements initialized.
Exceptions

ExceptionCondition
ArgumentException thrown if no constructor to the class can be found with a single IWebDriver argument

-or-

if a field or property decorated with the FindsByAttribute is not of type IWebElement or IList{IWebElement}.
Remarks

The class used in the T argument must have a public constructor that takes a single argument of type IWebDriver. This helps to enforce best practices of the Page Object pattern, and encapsulates the driver into the Page Object so that it can have no external WebDriver dependencies.
See Also

Reference