How to fully wait browser load after a form submission by EvaluateScriptAsync in CefSharp.OffScreen

355 Views Asked by At

I am using the below method to submit a form:

  var _Command = "document.querySelector(\"body > x > y > z\").shadowRoot.querySelector(\"d > form > ep-button\").shadowRoot.querySelector(\"button\").click()"
  JavascriptResponse scriptResult = await browser.EvaluateScriptAsync(_Command);

However this doesn't wait browser to fully load after command execution. How can I do that?

The command works I have tested

I am using .NET 7 and CefSharp.OffScreen

1

There are 1 best solutions below

0
On

You can use WaitForNavigationAsync for this purpose.

var navigationTask = browser.WaitForNavigationAsync();
var evaluateTask = browser.EvaluateScriptAsync($"window.location.href = '{url}';");

await Task.WhenAll(navigationTask, evaluateTask);

var navigationResponse = navigationTask.Result;
var executeResponse = evaluateTask.Result;

WaitForNavigationAsyncTests xUnit Tests for reference.