2010-01-21 84 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