2

What I am trying to do:

I am currently migrating my Selenium(Java) framework from a standard Page Object model + cucumber setup to a PageFactory + cucumber setup.

This is what I've done so far to try and make it work:

  • I Initiated my PageFactory.
  • I imported all required packages and dependencies.
  • I checked multiple online tutorials to make sure I have the right syntax.

The issue I run into:

My IDEA (IntelliJ) keeps giving me errors on the @FindBy annotations and failing to compile because of it.

When I mouse-over my @FindBy annotations it tells me "@FindBy not applicable to method"

When I try and run my test it gives me the following error on each occurence of the @FindBy annotation. "annotation type not applicable to this kind of declaration"

The code my question is about:

    package pageObjects;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;

public class AssociatedAlerts {


    public AssociatedAlerts(WebDriver driver) {
        PageFactory.initElements(driver, this);
    }

    @FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
    public WebElement firstAlertCheckboxSelected();
}

I must be missing something simple but I just can't seem to spot it. Any help would be much appreciated.

Thanks in advance.

1 Answer 1

3

You have an error in your syntax:

    @FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
    public WebElement firstAlertCheckboxSelected();

firstAlerchCheckboxSelected is NOT a method. It's a variable.

Change it to:

    @FindBy(css = "#Rabo_SelectedBatchSLTransactionrow0 > * > [type = 'checkbox']")
    public WebElement firstAlertCheckboxSelected;
10
  • 1
    Great catch (+1), Should nail the OP. Commented Feb 8, 2018 at 13:49
  • Thank you so much! It works like a charm now. And thank you for telling me the why behind it as well. Lesson learned.
    – Ceesiebird
    Commented Feb 8, 2018 at 14:18
  • @Ceesiebird Glad I could help :) You provided the very useful code example. Happy coding!
    – Fenio
    Commented Feb 8, 2018 at 14:22
  • @RafałLaskowski so let's say sometimes I wish to give some arguments with my WebElement, which I would normallly define in the () at the end of my method. How would I go about setting this up given the above code example?
    – Ceesiebird
    Commented Feb 19, 2018 at 7:45
  • @Ceesiebird Provide an example because it's too abstract :)
    – Fenio
    Commented Feb 19, 2018 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.