0

I know that selenium webdriver can do that:

var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.ClassName("someclass")));

can't I do that on my method? For example I have a method which takes a screenshot and compares with another picture. I want to wait until that method returns true.

So I have this code

while (WelcomeScreen(driver) != true)
{
    Thread.Sleep(1000);   
}

Can't I find any better solution?

gsiradze
  • 4,583
  • 15
  • 64
  • 111

1 Answers1

5

you can use the FluentWait, I am not good with C# so following code example is in Java. if you can convert it to C#, I think it might work.

 Wait wait = new FluentWait<WebDriver>(driver)
        .withTimeout(30, TimeUnit.SECONDS)
        .pollingEvery(5, TimeUnit.SECONDS)
        .ignoring(NoSuchElementException.class);

 wait.until(new Function<WebDriver, Boolean>() {
                public Boolean apply(WebDriver driver) {
                    return WelcomeScreen(driver)
                }
              }
 );
Gaurang Shah
  • 11,764
  • 9
  • 74
  • 137
  • 1
    thanks for answer. equivalent in c# will be this code: wait.Until((x) => { if(WelcomeScreen(driver)) return true; return false; }); – gsiradze Jun 13 '17 at 15:00
  • Is it possible to pass the method (in this case `public Boolean apply(WebDriver driver) { return WelcomeScreen(driver) }` as a parameter? – Happy Bird Jul 19 '17 at 08:18
  • @HappyBird what do you mean by passing the method, it returns the value returned by `WelcomeScreen` method. – Gaurang Shah Jul 19 '17 at 08:25
  • The code you have posted, I like this. I want to put it in a method "WaitUntilTrue" and to this method, I want to pass "Welcomescreen(driver)". I think I already found the answer by using an Action delegate (https://stackoverflow.com/questions/5414515/c-sharp-passing-a-method-as-a-parameter-to-another-method) – Happy Bird Jul 19 '17 at 08:30