Awesomium.NET: document not ready in DocumentReady event?

I use Awesomium 1.7.0.5 to load a page, fill in some text fields and click a button. I am trying to fill in a text box using an example from this thread: http://answers.awesomium.com/questions/857/webcontrol-type-in-webbrowser.html

Here is my code (I am using WPF control):

        private void WbAwsOnDocumentReady(object sender, UrlEventArgs urlEventArgs)
        {
            if (wbAws == null || !wbAws.IsLive)
              return;

            //Thread.Sleep(555);

            dynamic document = (JSObject)wbAws.ExecuteJavascriptWithResult("document");

            if (document == null)
              return;

            using (document)
            {
                dynamic textbox = document.getElementById("email");

                if (textbox == null)
                  return;

                using (textbox)
                {
                    textbox.value = "gaaffa"; 
                }

            }
        }

It works, but only with Thread.Sleep for 0.1-0.5 seconds. Otherwise, the document is empty (but not null) and / or the text field is null. What should I do? Why is it not ready in DocumentReadyEvent?

+5
source share
1 answer

Here's how I solved it:

     WbAws.LoadingFrameCompleted += OnLoadingFrameCompleted;
     WbAws.Source = new Uri("http://google.com");

private void OnLoadingFrameCompleted(...)
{ 
   if (webView == null || !webView.IsLive || 
         webView.ParentView != null || !e.IsMainFrame)
     return;

    LoadingFrameCompleted -= OnLoadingFrameCompleted;

    // do something
}

LoadingFrameCompleted DocumentReady , , , , . , IsMainFrame.

: , . , Thread.Sleep.

+5

All Articles