71522

Question:
Click on a link triggers an operation that creates new element. However, calling driver.findElement(By.id(""))
after click returns does not find it.
I have tried the following code to wait for the element to appear.
wait.until(new ExpectedCondition()
{
public Boolean apply(WebDriver webDriver) {
System.out.println("Searching ...");
return webDriver.findElement(By.id("itemType1")) != null;
}
});
But I still can't find it until timeout.
Answer1:You can maybe use the element.isDisplayed()
Så do it like this:
WebElement jrnrText = driver.findElement(By.id("id"))
if(jrnrText.isDisplayed()){
wait.until(presenceOfElementLocated(BY.id]("id")))
}
Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
return new Function<WebDriver, WebElement>() {
public WebElement apply(WebDriver driver) {
return driver.findElement(locator)
}
}
}