How to wait for page loaded #4870
Replies: 3 comments 2 replies
-
Or perhaps would it be waiting for navigation, when await Browser.WaitForNavigationAsync(); Because obviously if we just assume the new address is loaded and start jamming through elements, we are likely to encounter unexpected errors. |
Beta Was this translation helpful? Give feedback.
-
What we are doing specifically. The page has already loaded, but the elements we are interested are being AJAX loaded, as far as we can determine, after the fact. // Depends upon the bot status <div id="..."/> and back out to the associated server breadcrumbs.
var divBotStatus = await context.QuerySelectorAsync<HtmlDivElement>(S.BotStatus);
// TODO: do not necessarily want to get caught in a tight loop here
// TODO: but do not know what else to do right now
int badgeAttempts = 0;
HtmlSpanElement spanBadge = null;
// TODO: I think we will legit "not" see this span because it is AJAX filled in after the page has "loaded"
while (spanBadge is null)
{
//// TODO: may may not need to refresh the bot status div...
//divBotStatus = await context.QuerySelectorAsync<HtmlDivElement>(S.BotStatus)
++badgeAttempts;
spanBadge = await divBotStatus.QuerySelectorAsync<HtmlSpanElement>(S.SpanBadge);
}
var spanClassList = await spanBadge.GetClassListAsync();
Is there a better way to wait for the badge to arrive, And whether successful or warning or what not, we need that status for subsequent parts of the application to be available, let alone useful. |
Beta Was this translation helpful? Give feedback.
-
That's a tough one. Fully loaded is often very different depending on the page. There are a number of different strategies, which to use depends on the use case Basic (built in options).
CefSharp/CefSharp/WebBrowserExtensions.cs Line 624 in 19bb623 Advanced (CefSharp.Dom)
|
Beta Was this translation helpful? Give feedback.
-
I am currently watching some events, address changed, and so forth. I wish to respond when I see certain addresses changed, but I am not certain that the page has fully loaded, i.e.
Perhaps it has loaded, then I am not sure why this request would make sense at all. Or what is generally recommended to ensure that a page has loaded before being able to probe elements and such. Of course without a crystal ball knowing the page server, architecture, etc, but just in general.
I am getting a time out during this request for whatever reason. So it seems the page "is loading" so cannot exactly depend on some of the elements being there yet. But for it to just time out, I'm not sure what the parameters are telling us, the idle time? Justaposed with the timeout?
I have some vague notions maybe what I could tweak, but I'm afraid I would be shooting blinding in the dark. Any pointers would be appreciated.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions