从WatiN网站:
// 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();上面的示例运行得很好。但是,由于我不想打开浏览器窗口,因此我将上面的代码修改为使用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();TypeText行抛出了一个异常。知道出什么问题了吗?
发布于 2010-01-22 20:31:45
MsHtmlBrowser只是用来查找元素并读取它们的属性值。它不支持点击链接、输入文本、触发事件、没有会话状态或任何其他与普通浏览器交互的方式。所以我们只对它进行报废。
HTH,Jeroen
https://stackoverflow.com/questions/2110298
复制相似问题