Rayrun
← Back to Discord Forum

Is there a way to refresh the page until an element is shown?

maimai9336
maimai9336

Hi folks, I am looking for a way to refresh a page until an element is shown. This is for testing a workflow that has different elements on the page as time passes, but these elements will only appear if the page is refreshed.

This thread is trying to answer question "Is there a way to refresh a page until an element is shown for testing purposes?"

7 replies
disconnexus
disconnexus

@maimai9336 were either of the above helpful for you? If not, were you able to figure this out? I'm also curious of the solution as I'm trying to do something similar within my tests, waiting on an element to be visible on the page, but having to refresh until it is.

I asked something similar before. The guys gave me a pretty good approach let me find

Yep expect poll. What I did was

  1. Set timeout in the test for limit of 70s

  2. Perform the action and return certain responses

  3. Validate the response to be an Object if this is the expected result.

Otherwise return String and retry at interval of 10s, 20s, 30s

await expect.poll(async () => { try { perform the action return resultOfTheAction } catch (error) { return 'NA' } }, { // Custom error message, optional. message: 'custom message', // Poll for 60 seconds; intervals: [10_000, 20_000, 30_000], timeout: 60_000, }).toBeInstanceOf(Object);

Applying it in various scenarios by changing the action and the return verification.

For example: if my expected final page contains 2 Elements. Then my Objects array containing all the elements needs to have the return length of 2 .toEqual(2). If it doesn't cause it takes extra time to load, return 0 and retry

Hi, sorry forgot to mention I am using .NET not Node.js. Any suggestions?

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.