Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] How do we poll for some seconds if an element will become present? #918

Closed
NikkTod opened this issue May 7, 2022 · 3 comments
Labels

Comments

@NikkTod
Copy link

NikkTod commented May 7, 2022

Hello,

Can somebody help me with code example of the following situation:

I have a question form on which there could be follow up question depending on the answer of the first question.

So my issue is that I want to poll for let say 3 seconds if an element will become available after a click.

A saw that locator.isVisible timeout option is DEPRECATED, so how do we do it now?

@yury-s
Copy link
Member

yury-s commented May 9, 2022

If you know that the element should become visible the recommended way is to use web-first assertion:

assertThat(page.locator(".my-element")).isVisible();

Otherwise you can do a generic poll using page.waitForTimeout like this:

    Instant start = Instant.now();
    while (!locator.isVisible() && Duration.between(start, Instant.now()).getSeconds() < 3) {
      page.waitForTimeout(100);
    }

In the next version we may introduce generic poll method to simplify code like this.

@yury-s yury-s added the triaging label May 9, 2022
@NikkTod
Copy link
Author

NikkTod commented May 9, 2022

Hi @yury-s, thanks for the hints.

Usually I use web-first assertions, but they are not returning Boolean.

There are cases where I do not know if this element will become available, so I am using for example an if statement.

e.g. -> if (element.IsVisible) do something.

But as we know .isVisible() is returning immediately, so we need some time to wait for it.

Will try the waitForTimeout, but having generic poll method will be great.

Thanksss!

@mxschmitt
Copy link
Member

mxschmitt commented May 30, 2022

Closing since we have web-first assertions for that. I filed a separate feature request for assert.poll here: #940

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants