Inside the WebDriver support library, the PageFactory class provides a series of annotations that you can use when you create your page objects.
You can use this class to predefine a series of WebElement objects that can be used later in your test. The PageFactory class turns these WebElement objects into proxied objects using a Java Proxy class. When you try to use them, the annotations that you specify are used to transform these proxied objects into real WebElement objects that can be used in your tests. We need to do two things to use the PageFactory class:
- Annotate the variables that we want to proxy
- Initialize the proxied objects before we try to use them