2017-04-20 8 views
0

私は自動テストを作成しています。 私は、このガイドのおかげことをやっている: sukesh15.gitbooks.iocucumber selenium webdriver javaを使用すると、WebElementのpresenceOfElementを確認する方法

ここでは私のPageクラスの抽出物である:

public class TestCuCumBerPage { 

WebDriver driver; 

@FindBy(id = "display") 
private WebElement buttonDisplay; 

public void buttonDisplayClick() throws Throwable { 
    WebElement myDynamicElement = (new WebDriverWait(driver, 30))   
     .until(ExpectedConditions.presenceOfElementLocated(By.id("display"))); 

    buttonDisplay.click(); 
} 
} 

私はIDが "表示" を使用しました:

  • @FindBy宣言(WebElementに "buttonDisplay"を与える)
  • WebDriverWait

ことを避けるために、私は、IDと一定のBUTTON_DISPLAY_ID作成しました:

public class TestCuCumBerPage { 

WebDriver driver; 

private final String BUTTON_DISPLAY_ID = "display"; 
@FindBy(id = BUTTON_DISPLAY_ID) 
private WebElement buttonDisplay; 

public void buttonDisplayClick() throws Throwable { 
    WebElement myDynamicElement = (new WebDriverWait(driver, 30))   
     .until(ExpectedConditions.presenceOfElementLocated(By.id(BUTTON_DISPLAY_ID))); 

    buttonDisplay.click(); 
} 
} 

がより良い方法は、この WebElement myDynamicElement =(新しいWebDriverWait(ドライバ、30)のような例を何かのために、あるのを)
.until(予想される条件。 presenceOfWebElement(buttonDisplay));

(私は挨拶がhereを説明した)あなたの助けを

おかげ

答えて

0
public boolean isElementPresent(WebElement element){ 
    try{ 

    WebElement; 

    return true; 

} 
catch(Excception e){ 

System.out.println("Element not present!!"); 
return false; 

} 
} 
+0

いくつかの説明を含めるようにあなたの答えを編集してください。コードのみの回答は、今後のSO読者の教育にはほとんど役に立ちません。あなたの答えは低品質であるためにモデレーションキューにあります。 – mickmackusa

関連する問題