2010-10-07 56 views
0

你好我試圖登錄到一個網站使用WebBrowser控件目前它的工作完美登錄,但當我通過使用瀏覽或使WebBrowser點擊鏈接去程序化的網站的不同頁面我還沒有登錄?我猜它與cookies或某事有關,但一直沒能在Google上找到任何有關如何使其工作的信息。C#Webbrowser導航問題

HtmlElement content = this.wb.Document.GetElementById("content"); 
    HtmlElement username = content.Document.All["username"]; 
    username.SetAttribute("value", "Username"); 
    HtmlElement pass = content.Document.All["password"]; 
    pass.SetAttribute("value", "Password"); 
    HtmlElement goButton = content.Document.All["submit"]; 
    goButton.Focus(); 
    SendKeys.Send("{ENTER}"); 

正在我所擁有的。 啊現在我試圖使用它現在無法正常工作,以獲得從它有什麼文本的按鈕,而不是它是什麼樣式?

回答

0

我認爲你的代碼可以與firefox一起使用,但不能在IE上運行。所以,請修改你的代碼如下。希望有所幫助:)

HtmlElement content = this.wb.Document.GetElementById("content"); 
HtmlElement username = content.Document.All["username"]; 
username.SetAttribute("value", "Username"); 
HtmlElement pass = content.Document.All["password"]; 
pass.SetAttribute("value", "Password"); 

HtmlElementCollection htmlCol = webBrowser.Document.GetElementsByTagName("input"); 
foreach (HtmlElement el in htmlCol) 
{ 
    if ((el.Name == "submit") && (el.GetAttribute("value") == "Value of submit button")) 
    { 
     el.InvokeMember("click"); 
     break; 
    } 
}