0

I managed to add a script below to refresh the page if an element is not visible using automation script, and this works but I want it to stop refreshing after a period of time e.g 20 seconds or a number of times if the element is not visible so the test will fail and so it doesn't end up infinitely refreshing. Any advise on how to achieve this with an example please or how to amend the code below to make it work? I tried introducing a timeout to the reloadAsync method but it doesn't accept it.

do
{
    await Page.ReloadAsync(); 
}
while (!await Page.IsVisibleAsync("input[name='elementname']")) ;
ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
hm9
  • 37
  • 8
  • The documentation suggests it should accept a timeout: https://playwright.dev/dotnet/docs/api/class-page#page-reload – ProgrammingLlama Dec 27 '21 at 14:20
  • I m using Page.ReloadAsync(); This doesnt accept any parameter for timeout – hm9 Dec 27 '21 at 14:46
  • That's not what the documentation I linked to says. The documentation says that it accepts an object that has a `Timeout` property. – ProgrammingLlama Dec 27 '21 at 14:46
  • I tried using the default timeout after the load but it never timesout and just keep refreshing permanently as shown in this code: await Page.ReloadAsync(); Page.SetDefaultTimeout(5000); – hm9 Dec 27 '21 at 14:49
  • I've checked and the `ReloadAsync` method definitely does take a `PageReloadOptions` that takes a `Timeout` value. – ProgrammingLlama Dec 27 '21 at 14:54
  • So something like: await Page.ReloadAsync(PageReloadOptions: 5000); ? – hm9 Dec 27 '21 at 14:58
  • No, more like `await Page.ReloadAsync(new PageReloadOptions() { Timeout = 5000 });` if I'm reading the documentation correctly. – ProgrammingLlama Dec 27 '21 at 14:59
  • Ok thanks. It still doesnt timeout? It may be because the refresh is happening quickly that it doesnt timeout? this is what i have now: do { await Page.ReloadAsync(new PageReloadOptions() { Timeout = 5000 }); } while (!await Page.IsVisibleAsync("input[name='element']")) ; – hm9 Dec 27 '21 at 15:09
  • Any idea how this can be resolved please? thanks – hm9 Dec 27 '21 at 16:24

0 Answers0