cefSharp Detect when entire page is loaded - c#

I need to be able to detect when an entire page is loaded. The page has JavaScript that executes when you browse to it as well. And I must wait for that to finish loading as it adds HTML Elements to the page.
I have tried the below event. But this is trigger when the main page loads and doesn't care about the javascript.
browser.LoadingStateChanged
So I also tried count these to know when all the frames on a page where loaded. But it still wasn't spot on.
browser.FrameLoadStart += OnFrameLoadStart;
browser.FrameLoadEnd += OnFrameLoadEnd;
Any suggestions

Ended up using javascript to wait for element to display and then continue

Related

Wait for window.onload event using Selenium Webdriver

I need a solution how to wait until the web page is fully loaded. And exactly after that, waiting no longer, I need to perform actions with a web page: get URL of loaded page, check cookie, click <a> elements so on
I use the following code before work with loaded page:
IWait<IWebDriver> wait=new WebDriverWait(drv, TimeSpan.FromSeconds(30.00));
wait.Until(d => ((IJavaScriptExecutor)drv).ExecuteScript("return document.readyState").Equals("complete"));
But this code does not wait in 100% cases until full load of a page in Chrome, and does not work in Internet Explorer!
Could you please offer better solution
Thanks for an answer in advance!
document.readyState does not always return the actual status of page load completion. see if you can wait on a particular element on the page, perhaps which gets loaded last on the page.

Wait till the GeckoFX Webbrowser has loaded

I want to automate a few tasks on my website with GeckoFX for some testing.
That should happen when I click a button and everything should be automated after that button click.
This includes clicking buttons where the page refreshes so the code has to wait till the page has loaded and that's where my problem is.
If I do it like that:
geckoWebBrowser1.Navigate("http://mywebsite.com");
GeckoInputElement searchText = new GeckoInputElement(geckoWebBrowser1.Document.GetElementsByName("searchbox")[0].DomObject);
searchText.Value = "GeckoFx";
I get an error, so how can I put it that the code after .Navigate waits till the webbrowser has fully loaded the page?
You can use DocumentCompleted Method to perform your automatic operations.
private void geckoWebBrowser1_DocumentCompleted(object sender,EventArgs e)
{
// Here you can add the coding to perform after document loaded
}
For example : First initiate the browser to google page by geckoWebBrowser1.Navigate("https://www.google.com");
After google page loaded you can do the following in document_completed method:
GeckoInputElement search =new GeckoInputElement(geckoWebBrowser2.Document.GetElementsByName("q")[0].DomObject);
GeckoInputElement button = new GeckoInputElement(geckoWebBrowser2.Document.GetElementsByName("btnG")[0].DomObject);
search.focus();
search.Value = "Master Blaster Sachin";
button.Click();
so it will search the value you given automatically after the google page loaded. Like that you can modify the program as per your logic. Hope it helps..
I would go an use a product like Selenium http://seleniumhq.org/. It's free open source web testing which is scriptable.

How to determind if the web page is loaded completely in web browser?

I am working on windows form application which is HTML base user interface.
I need to know when the web page is loaded completely.
I've tested many web browser events like DocumentCompleted, IsBusy, ReadyState but none of them responded what i expected.
If you can use the jQuery library, then it's really simple.
$(document).ready() {
//your page is fully loaded
};
Otherwise you'll have to have to rely on different methods based on the browser you're using. Since it's a windows form application, I'm assuming the rendering engine you're using is IE based. If that's then this might work for you:
if (document.attachEvent)
{
document.attachEvent("onreadystatechange", function()
{
if (document.readyState === "complete")
{
document.detachEvent("onreadystatechange",
arguments.callee);
/* code to run on load */
}
});
}
You can find other browser dependent solutions here, if you're interested:
http://dean.edwards.name/weblog/2006/06/again/
Chamika Sandamal is correct - you should use DocumentComplete event BUT - check the 'sender' object. The very last 'complete' event is coming from 'browser' object itself and not from images, text, etc.. that fire it on loading. After all elements on page will fire DocumentComelete event the very last event will come from browser itself. If you could cast the 'sender' to browser object - here you go - it's browser loading complete event. Just notice that in case you have any 'frame' tags in HTML they will rise different DcoumentComplete events after browser Complete event. I think 'frame' considered as another HTML page so it will have itself 'complete' events..

C# ASP.NET Slow AJAX loading

When I call a page with AJAX, everything goes fast and well. But if I have a page (for testing purposes) with the following code:
for(int i = 0; i < int.MaxValue; i++)
{}
the page loading is longer, which is obvious. But then, when I load a page that only sets a text on a label, it takes longer (about 5 seconds), but this ain't the case if I call this page before calling the test page (with the for loop).
So, all the loading goes fast, except when I call the test page. From there on every page loads slow. How come?
If that for...next loop is in the pageload of your page, ALL ajax queries will have to run that same loop; you should put any long-running processes inside a this.IsPostPack == false if statement, and then persist that data in viewstate if you need it during subsequent postbacks.
I found the solution. It was bad programming. With AJAX I was loading Web User Controls (ascx files). I saved the controls in the ViewState and in my page load I loaded these controls again. So per page load the previous user control was loaded. By removing this method in the page_load my problem is solved.
Thanks for the effort though.

c# Ajax Lazy Loading

I need to populate 4 GridViews on an aspx page, but I only bind a datatable to one of them on page load. I need to pupulate the other 3 after page load.
does anyone know the best way to do this using ajax ?
Currently I'm using javascript to __doPostBack on a button that pupulates the 3 GridViews but unfortunately this forces a full page load even when using an update panel. I need the page to load, and then populate the GridViews as the datatables are returned.
any suggestions would be much apreciated.
The way you are doing it should work ok, although using jquery to populate a div via the $("#targetDiv").load("contentUrl"); function may be a cleaner way to do it. Anyway, in order to get your current implementation working, there could be a few things you want to look at:
I assume EnablePartialRendering is true on your ScriptManager (always worth checking!).
Make sure the eventTarget for the __dopostback call is set up as an async trigger for your update panels or that it is inside the UpdatePanel if you are only using one UpdatePanel. (See here for details)
Try returning false from the javascript code that executes in the onclick event handler if you have attached this to a button, to make sure the form is not being submitted normally by your browser when you click the button.
If I understand the question properly, you want the data to load after the page is in the browser. If this is the case, then you can fire an event with JavaScript when the page loads on the client.
One method I've used is to put a hidden (with CSS, not any property) button on the page and 'clicking' it with javascript. The event of the button click event will need to be wired in the page's code. Also the button would have to be in an update panel that either contains the grids you want to be bound or has the appropriate triggers to cause them to reload.
You might look at JQuery to get manage when this code gets fired. The $(document).ready(function(){ /* Your code here... */ }); method will fire after the entire DOM is available, which is faster than waiting on the entire page to load (images and so forth).

Categories

Resources