2010-01-21 85 views
0

从华廷网站:华廷:MsHtmlBrowser不会的TypeText

// 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线抛出异常。任何想法有什么不对?

+0

什么是例外?它没有找到TextField,从而引用空指针? – 2010-01-21 17:47:13

回答

1

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

HTH, Jeroen

+0

Jeroen,谢谢你的澄清。我需要从Web服务“键入文本”等。我可以用IE和FF类来做到吗?我能以某种方式使用这些浏览器来运行“无头”吗? – StackOverflowNewbie 2010-01-23 05:38:38