c# - Web browser.navigate("www.somesite.com") Load page in window but Webbrowser.Document returns Null -
I am using web browser controls in a window form. Here I am navigating to some sites with 1 parameter. This page is loading in the web browser, but when I am looking for webbrowser.document to search some HTML tags, it is showing the taps for it. I want to find all the anchor tags in the webbrowse loaded page. The following is my code.
webChatPage.Navigate (Configuration Manager. AppSettings ["ServerURL"]. ToString () + "/somepage.php?someparameter=" + sessionId); HtmlDocument hDoc = webChatPage.Document; // hDoc = NULL Debugging HtmlElementCollection aTag = hDoc.Links; MessageBox.Show (aTag.Count.ToString ());
If there is a solution then help me.
Events must be handled to notify you when the document starts loading:
When a newly discovered event occurs, the new document has started loading, which means that you have loaded the document in the document, document, and document stream properties. Edit
: As Brianle comments in a comment, a better solution would be to handle this phenomenon because the document is loading from this point, then your code will be something like this:
< Code> webChatPage.DocumentCompleted + = (o, e) = & gt; {// When the document HtmlDocument hDoc = webChatPage.Document has finished loading; HtmlElementCollection aTag = hDoc.Links; MessageBox.Show (aTag.Count.ToString ()); } String url = ConfigurationManager.AppSettings ["ServerURL"]. ToString () + "/somepage.php?someparameter=" + sessionId; WebChatPage.Navigate (URL);
Comments
Post a Comment