add waitNetworkIdle

This commit is contained in:
Haiping Chen 2024-09-08 22:02:52 -05:00
parent f7c77ee11c
commit 8ddb0d4ace
2 changed files with 8 additions and 5 deletions

View file

@ -203,15 +203,18 @@ public class PlaywrightInstance : IDisposable
/// <param name="ctxId"></param>
/// <param name="timeout">seconds</param>
/// <returns></returns>
public async Task Wait(string ctxId, int timeout = 60)
public async Task Wait(string ctxId, int timeout = 10, bool waitNetworkIdle = true)
{
foreach (var page in _pages[ctxId])
{
await page.WaitForLoadStateAsync(LoadState.DOMContentLoaded);
await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new PageWaitForLoadStateOptions
if (waitNetworkIdle)
{
Timeout = 1000 * timeout
});
await page.WaitForLoadStateAsync(LoadState.NetworkIdle, new PageWaitForLoadStateOptions
{
Timeout = 1000 * timeout
});
}
}
await Task.Delay(100);
}

View file

@ -4,7 +4,7 @@ public partial class PlaywrightWebDriver
{
public async Task<BrowserActionResult> ActionOnElement(MessageInfo message, ElementLocatingArgs location, ElementActionArgs action)
{
await _instance.Wait(message.ContextId);
await _instance.Wait(message.ContextId, waitNetworkIdle: false);
var result = await LocateElement(message, location);
if (result.IsSuccess)
{