Reputation: 21
I did come across this issue here but according to the thread the "error was gone, and I don't know how it was fixed"... got error while trying to use @FindBy annotation in selenium
Here is the code I have written. The strange thing is I already have another web element defined on the page object class and it works fine. I just can't seem to understand what the problem is. I am just learning selenium and have never encountered this issue before. I have tried searching the web for answers but cannot seem to find an answer for this particular issue.
This is the first web element on the page object class and it works fine.
// Profile button element
@FindBy(xpath="//div[@class='container']//nav//li[2]//a[1]")
@CacheLookup // is used to improve the performance
static WebElement profileBtn;
With this element (on same page object class) I get "The annotation @FindBy is disallowed for this location". I have tried restarting eclipse and cleaning the project but it will not allow this second element.
@FindBy(xpath="//div[@id='stateDropdown-styler']//div[@class='jq-selectbox__trigger']")
@CacheLookup // is used to improve the performance
WebElement clickProvinceDropDownArrow()
Upvotes: 2
Views: 4788
Reputation: 5207
See the definition of @FindBy annotation. It is applicable to fields and classes only, not to methods. It reduces the amount of code that you would otherwise need to write to locate an element and to store it into a member variable.
If you are using page object pattern, then define a member variable with this annotation. If you want to make this element available outside of your page object, implement a getter method that returns this member variable.
@FindBy(xpath="//div[@id='stateDropdown-styler']//div[@class='jq-selectbox__trigger']")
private WebElement clickProvinceDropDownArrow;
public WebElement getClickProvinceDropDownArrow() {
return clickProvinceDropDownArrow;
}
Upvotes: 3