Skip to content

Instantly share code, notes, and snippets.

@SarahElson
Last active November 1, 2023 12:26
Show Gist options
  • Save SarahElson/5cdc25fbc7b3f9a1245fb8807e51c3b6 to your computer and use it in GitHub Desktop.
Save SarahElson/5cdc25fbc7b3f9a1245fb8807e51c3b6 to your computer and use it in GitHub Desktop.
How to Use @findby Annotation in Selenium Java
public class MyAccountPage {
public MyAccountPage(final WebDriver driver) {
PageFactory.initElements(driver, this);
}
@FindBy(css = "#content > div:nth-child(1) h2")
@CacheLookup
private WebElement myAccountTitle;
public String getMyAccountPageTitle() {
return this.myAccountTitle.getText();
}
@FindAll({
@FindBy(how = How.LINK_TEXT, using = "Logout"),
@FindBy(how = How.CSS, using = "#column-right > div > a:nth-child(14)")
})
private WebElement logoutLink;
public void logoutFromEcommercePlayground() {
this.logoutLink.click();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment