WatiN:MsHtmlBrowser不会是TypeText

时间:2010-01-21 15:17:37

标签: c# .net watin

来自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行抛出异常。知道什么是错的吗?

1 个答案:

答案 0 :(得分:1)

MsHtmlBrowser仅用于查找元素并读取其属性值。不支持单击链接,键入文本,触发事件,没有会话状态或任何其他与普通浏览器交互的方式。所以我们只是为了报废。

HTH, 的Jeroen