0

I'm writing an automatic test. I'm doing that thanks to this guide : sukesh15.gitbooks.io

Here is an extract of my Page class :

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();  
}
}

I've to use the id "display" :

  • in the @FindBy declaration (give the WebElement "buttonDisplay")
  • in the WebDriverWait

To avoid that, I've created a constant BUTTON_DISPLAY_ID with the 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();  
}
}

Is there a better way, for example something like this WebElement myDynamicElement = (new WebDriverWait(driver, 30))
.until(ExpectedConditions.presenceOfWebElement(buttonDisplay));

( I found a greet explain here)

Thanks for your help

Community
  • 1
  • 1
MichelBen
  • 21
  • 3

1 Answers1

0
public boolean isElementPresent(WebElement element){
  try{

     WebElement;

     return true;

}
catch(Excception e){

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

}
}
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
  • Please edit your answer to include some explanation. Code-only answers do very little to educate future SO readers. Your answer is in the moderation queue for being low-quality. – mickmackusa Apr 21 '17 at 17:06