tags:

views:

98

answers:

1

From the WatiN website:

  // Open a new Internet Explorer window and
  // goto the google website.
  IE ie = new IE("http://www.google.com");

  // Find the search text field and type Watin in it.
  ie.TextField(Find.ByName("q")).TypeText("WatiN");

  // Click the Google search button.
  ie.Button(Find.ByValue("Google Search")).Click();

  // Uncomment the following line if you want to close
  // Internet Explorer and the console window immediately.
  //ie.Close();

The above sample works just fine. However, since I do not want to open up a browser window, I modified the above code to use MsHtmlBrowser:

        // goto the google website.
        var ie = new MsHtmlBrowser();
        ie.GoTo("http://www.google.com");
        // Find the search text field and type Watin in it.
        ie.TextField(Find.ByName("q")).TypeText("WatiN");

        // Click the Google search button.
        ie.Button(Find.ByValue("Google Search")).Click();

The TypeText line is throwing an exception. Any idea what's wrong?

+1  A: 

Hi,

The MsHtmlBrowser is only there to find elements and read their attribute values. There is no support for clicking a link, typing text, firing events, no session state or any other way of interact like with a normal browser. So us it for scrapping only.

HTH, Jeroen

Jeroen van Menen
Jeroen, thanks for the clarification. I need to "type text", etc. from a web service. Can I do that with the IE and FF classes? Can I somehow use those browsers to run "headless?"
StackOverflowNewbie