C#Webbrowser导航问题

时间:2010-10-07 03:10:41

标签: c# browser

你好我试图使用WebBrowser控件登录一个站点,目前它正在完美地登录,但是当我通过使用导航或者使用WebBrowser点击链接时我没有登录时以编程方式访问该站点的不同页面还有吗?我猜这与饼干或其他东西有关但却无法在Google上找到如何使其发挥作用的任何内容。

   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}");

目前我拥有的是什么。 啊,到现在为止我试图使用它现在无法正常工作,无论如何从它的文本中获取一个按钮而不是它的样式呢?

2 个答案:

答案 0 :(得分:0)

作为比较,如果您使用iMacros for Internet Explorer记录此序列,它是否有效?

答案 1 :(得分: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;
    }
}