WatiN: MsHtmlBrowser will not TypeText
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 u开发者_Python百科se 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?
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
精彩评论