selenium-webdriver Using @FindBy annotations in Java

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Syntax

  • CLASS_NAME: @FindBy(className = "classname")
  • CSS: @FindBy(css = "css")
  • ID: @FindBy(id = "id")
  • ID_OR_NAME: @FindBy(how = How.ID_OR_NAME, using ="idOrName")
  • LINK_TEXT: @FindBy(linkText= "text")
  • NAME: @FindBy(name= "name")
  • PARTIAL_LINK_TEXT: @FindBy(partialLinkText= "text")
  • TAG_NAME: @FindBy(tagName="tagname")
  • XPATH: @FindBy(xpath="xpath")

Remarks

Note that there are two ways of using the annotation. Examples:

@FindBy(id = "id")

and

@FindBy(how = How.ID, using  ="id")

are equal and both look for element by its ID. In case of ID_OR_NAME you can only use

@FindBy(how = How.ID_OR_NAME, using ="idOrName")

PageFactory.initElements() must be used after page object instantiation to find elements marked with @FindBy annotation.



Got any selenium-webdriver Question?