Selenium webdriver isElementpresent方法与FindBy

Selenium webdriver isElementpresent方法与FindBy,selenium-webdriver,Selenium Webdriver,我必须使用这种方法 public boolean isElementPresent(By by) { return driver.findElements(by).size()!=0; } 但必须使用@FindBy public static final String addColorText="Add a color"; @FindBy(linkText = Data.ProductDetailData.addColorText) protected By addColorPrese

我必须使用这种方法

public boolean isElementPresent(By by) {
    return driver.findElements(by).size()!=0;
}
但必须使用@FindBy

public static final String addColorText="Add a color";
@FindBy(linkText = Data.ProductDetailData.addColorText)
protected By addColorPresent;
打这个电话的时候

 if (common.isElementPresent(addColorPresent))
获取NullpointerException(by为空)。我可以使用FindBy按对象返回吗?
任何输入请

我想你想要的是

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

FindBy应该返回WebElement.By.linkText(addColorText)接受常量吗?输入字符串有编译错误。它对我来说很好。它们必须是类字段(在类内部,但在函数外部)。谢谢,这个修复程序成功了。我在不断的声明中犯了一个错误。