liveBook · Manning

@FindBy annotation

As explained in Software Testing with Generative AI

A Selenium page-object annotation that specifies how a web element is located.

@FindBy specifies how a Selenium WebElement is located inside a Page Object. With PageFactory, annotations such as @FindBy(id = "name") connect Java fields to HTML elements and keep interaction methods readable. section 7.1.2

Common uses include:

  • Generate annotation-based page classes from supplied HTML by stating the required Java, Selenium, PageFactory, and locator constraints. section 7.1.2

Contact form

A ContactFormPage initializes PageFactory and declares @FindBy(id = "name") for nameInput and @FindBy(id = "submitContact") for submitButton; methods then enter values and submit the form.

How Software Testing with Generative AI covers it

How deep it goes
Demonstrates id and className locators, PageFactory initialization, interaction methods, and collection counting without detailing annotation internals.
Examples
Uses contact, login, and message pages with id, className, and list-based element declarations.
What it assumes
Assumes Java, Selenium, PageFactory, WebDriver, WebElement, and basic HTML locator knowledge.
What you can do after
Build it from scratch by translating HTML controls into annotated Page Object fields and wrapping them in interaction methods.
How it connects
Connects Selenium, Page Object, PageFactory, WebDriver, WebElement, and HTML locators.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Software Testing with Generative AI. The section links point to the parts of the book it draws on.