1

Scenario is that when i click start button starts this thread:

var t = new Thread(get_webbrowser_page);
t.SetApartmentState(ApartmentState.STA);
t.Start();

And start this function:

public void get_webbrowser_page()
{
    WebBrowser browser = new WebBrowser();
    browser.Navigate("http://www.google.com");
    string htmla = "as";
    browser.DocumentCompleted += (s, e) =>
    {
        var html = browser.DocumentText;
        htmla = html.ToString();
    };
    MessageBox.Show("ASD=" + htmla);
}

My mission is to simulate a click on href element but i can't do it because DocumentText is always empty.

I've red this WebBrowser - empty DocumentText question but it doesn't works for me. Where I'm wrong?

Community
  • 1
  • 1
aggenerale
  • 15
  • 3

1 Answers1

0

First, put the messagebox inside the event handler as the comment from Pragmateek suggest. One note, the DocumentCompleted event is firing per frame/iframe. It's good to know. See this question/answer: https://stackoverflow.com/a/3431520/767926

Community
  • 1
  • 1
jmelhus
  • 1,130
  • 2
  • 12
  • 28
  • yes, didn't know it but i tried also with a very simple html page (without any frame/iframe/other) and DocumentText was always empty – aggenerale Jun 19 '13 at 22:53
  • ok, changed my code but now it doesn't show me nothing: can't wait forever (usually it load the page in half second)... – aggenerale Jun 19 '13 at 22:58