Wait for element in webdriver

selenium-webdriverwebdriver

I followed what was written here:
WebDriver Selenium API: ElementNotFoundErrorException when Element is clearly there !

My code looks like:

    Function<WebDriver, WebElement> presenceOfElementLocated(final By locator) {
    return new Function<WebDriver, WebElement>() {
        public WebElement apply(WebDriver driver) {
            return driver.findElement(locator);
          }
       };
    }

   ....... 

   driver.get(baseUrl);

   WebDriverWait wait = new WebDriverWait(driver, 10);
   wait.until(presenceOfElementLocated(By.className("classname")));
   findByClassAndName(driver, "x-tree3-node-text", "Name1").click();

Problem is, that is does not seem to do anything. It doesn't work and i can't even see slightest trace of waiting for webpage gui. i got the same with implicit wait through timeouts… Anyone could help?

Best Answer

You have to catch Throwables throwed from ExpectedCondition or your Function (the apply() methods is good place for that) and return null so Wait.until() continues to run - see http://rostislav-matl.blogspot.com/2011/05/moving-to-selenium-2-on-webdriver-part.html for detailed example.

Related Topic