Using Page Factory with Page Object

The code that we learned to write earlier can be quite verbose. To clean up our code, we can start to use Page Factories. This allows us to annotate variables in our page objects about how to search the page. It means that we don't need to have the complete WebElement element = driver.findElement(...); code all over the file. We can change it to:

@FindBy(how=How.ID, using="foo")
WebElement foo;

As you can see, this can make our code slightly easier to read and more maintainable. If you regularly use other languages (such as Ruby or Python), you will notice that they don't have the PageFactory support project. This is because these languages don't have Factory constructs in the language. They are not idiomatic ...

Get Learning Selenium Testing Tools - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.