2010-10-07 58 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; 
    } 
}