1

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.

peter_budo
  • 1,748
  • 4
  • 26
  • 48
sandyli
  • 11
  • 2
  • Could it be possible that the call to findElement happens before the element is actually added ? Does wait call the 'apply' function several times, or only once ? – phtrivier Jun 09 '11 at 12:11

1 Answers1

0

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)
        }
    }
}
Nyegaard
  • 1,309
  • 3
  • 16
  • 24