Selenium: annotation type not applicable to this kind of declaration Selenium: annotation type not applicable to this kind of declaration selenium selenium

Selenium: annotation type not applicable to this kind of declaration


The reason for that being that the annotation is not applicable to local variables.

Further, the actual definition of the annotation in the documentation is :

@Retention(value=RUNTIME)@Target(value={FIELD,TYPE})public @interface FindBy

So, seemingly the annotation would still be applicable to fields. You can fix the same, by moving the variable to the global level (class attribute) as:

class WelcomePage {    @FindBy(partialLinkText = "Books")    private WebElement books;    .... // everything else    void populateCatalogue() {        // use 'books' here    }}