1
votes

at first:
- Selenium 2.0 with Webdriver
- for IExplorer, Chrome and Firefox
- current Webdriver and Selenium dll's
- Windows 8.1
- Visual Studio 2013 C#

i would test my site. The pages will be loaded with ajax. If i would change the page, it will be display a loading div (div #wartenDialog). Now i would wait while display this div, before i change to next page.

the problem is, sometimes there is a small delay until show loading div and by a fast computer/internet there is no loading div.

i have try this functions:

public static void WaitWhileElementVisible(RemoteWebDriver _driver, By _locator)
{
  WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromMilliseconds(timeout));
  wait.Until(drv => !Exists(drv, _locator));
}

private static bool Exists(IWebDriver _drv, By _locator)
{
  return (ExpectedConditions.ElementIsVisible(_locator) != null);
}

Now it's always run in Timeout.

1
You should show also your relevant HTML and how you call WaitWhileElementVisible with parameters. Also I do not understand why you create custom Exists method with parameter IWebDriver _drv that is not used at all. - Vojtěch Dohnal
the _drv is a leftover from an other try. i had use the _drv.FindElement(_locator) methode - Gamer2015

1 Answers

0
votes

Your approach to wait for element to visible is correct. But a little modification to your code will do the trick.

public static void WaitWhileElementVisible(RemoteWebDriver _driver, By _locator)
{
    WebDriverWait wait = new WebDriverWait(_driver, TimeSpan.FromMilliseconds(timeout));
    wait.IgnoreExceptionTypes(typeof(WebDriverTimeoutException));
    wait.Until(drv => !Exists(drv, _locator));
}

IgnoreExceptionTypes() will ignore the provided exception type. This code is working for me.

Hope this resolve your issue.