O'Reilly logo

Mastering Selenium WebDriver by Mark Collin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Introducing the Java PageFactory class

Inside the WebDriver support library, there is a PageFactory class that provides a series of annotations, which can be used when you create page objects.

You can use this class to predefine a series of WebElements, which 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, which can be used in your tests. We need to do the following 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

Using the PageFactory annotations ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required