I am new to java.
The only difference I can see is the webelement initialisation and nothing apart from that. Both can be used to access the class variables and methods.
Page Factory uses Java Reflection API
. It also has 2 public constructors for developers. One accepts already instantiated object as an argument. The second allows you to pass Object.class
which is not an instance, it's more like a schema of a class.
PageFactory.initElements(driver, this);
The above method accepts the instance of Page Object, already created instance. Then, it gets it's a schema, reads fields and initializes them based on @FindBy
annotations.
PageFactory.initElements(driver, PageObject.class)
The above class already has the schema so it initializes the fields and returns a newly created instance of PageObject
class.