Sree
Sree

Reputation: 121

isElementpresent method with FindBy

I have to use this Method

public boolean isElementPresent(By by) {
    return driver.findElements(by).size()!=0;
}

but have to use @FindBy

public static final String addColorText="Add a color";
@FindBy(linkText = Data.ProductDetailData.addColorText)
protected By addColorPresent;

when calling this

 if (common.isElementPresent(addColorPresent))

Getting NullpointerException(by is coming null). Can I use FindBy to return By object? Any inputs pls

Upvotes: 0

Views: 307

Answers (1)

JeffC
JeffC

Reputation: 25644

I think what you want is

public static final String addColorText = "Add a color";
@FindBy(linkText = addColorText)
protected By addColorPresent = By.linkText(addColorText);

Upvotes: 2

Related Questions