2015-10-16 29 views
0

我不得不使用此方法isElementpresent法FindBy

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

,但有調用這個

if (common.isElementPresent(addColorPresent)) 

獲得NullPointerException異常(由快到空時使用@FindBy

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

)。我可以使用FindBy來返回By對象嗎? 任何輸入PLS

+0

FindBy應該返回WebElement。 – Turcia

回答

2

我想你想要的是

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

做By.linkText(addColorText)接受一個常量我得到編譯錯誤輸入字符串。 – Sree

+0

它適合我。他們必須是類字段(在一個類中但在一個函數之外)。 – JeffC

+0

感謝此修復工作。我在不斷的聲明中犯了一個錯誤。 – Sree