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