Why does WebBrowser.Navigate returns null HttpDocument?
I have tried:
var browser1 = new WebBrowser();
browser1.Navigate("https://zikiti.co.il/");
HtmlDocument document = browser1.Document;
But browser.Document
is null.
Why?
What am I doing wrong ?
public static void FillForm()
开发者_开发百科 {
browser1 = new WebBrowser();
browser1.Navigate(new Uri("https://zikiti.co.il/"));
browser1.Navigated += webBrowser1_Navigated;
Thread.CurrentThread.Join();
}
private static void webBrowser1_Navigated(object sender,
WebBrowserNavigatedEventArgs e)
{
HtmlDocument document = browser1.Document;
System.Console.WriteLine();
}
The application is stuck. Btw, is there any easier way to fill and submit this form? (I cannot see the request header in Fiddler as the page is always blocked by JS).
Because it takes time to download the html. The amount of time nobody ever wants to wait for, especially a user interface thread, the hourglass won't do these day.
It tells you explicitly when it is available. DocumentCompleted event.
You have to pump a message loop to get that event.
Because Navigate
is asynchronous, and the navigation has not even started by the time you read the Document
property's value.
If you look at the example on that page, you will see that to read the "current" URL it needs to subscribe to the Navigated
event; same applies to reading Document
. The documentation for this event states:
Handle the Navigated event to receive notification when the WebBrowser control has navigated to a new document. When the Navigated event occurs, the new document has begun loading, which means you can access the loaded content through the Document, DocumentText, and DocumentStream properties.
精彩评论