1

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?

1 Answer 1

6

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)
                }
              }
 );
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for answer. equivalent in c# will be this code: wait.Until((x) => { if(WelcomeScreen(driver)) return true; return false; });
Is it possible to pass the method (in this case public Boolean apply(WebDriver driver) { return WelcomeScreen(driver) } as a parameter?
@HappyBird what do you mean by passing the method, it returns the value returned by WelcomeScreen method.
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 (stackoverflow.com/questions/5414515/…)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.