I have a script below that refreshes the page automatically 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. The code below works if the element is visible but if the element is not visible, it keeps refreshing infinitely. Any idea how to resolve it please ? Thanks
do {
await Page.ReloadAsync(new PageReloadOptions() { Timeout = 5000 }); }
while (!await Page.IsVisibleAsync("input[name='elementname']"))
Thank you. I may need to add an if statement after the while since it just executes the next block of code but i want it to exit if it fails to load the element ?