WebBrowser无法单击按钮登录网站

时间:2013-10-23 11:58:55

标签: c# .net winforms webbrowser-control

这适用于Visual Studio Express 2012中的Desktop C#应用程序。

我正在尝试使用webBrowser控件自动登录到各个网站,但我无法找到LogIn按钮并为此特定网站发出“点击”。我能够找到用户名和密码字段,并为那些没有问题的人填充值。只是我似乎无法发出“点击”来完成登录。

相关网站为https://www.my.telstra.com.au/myaccount/home?red=/myaccount/

使用谷歌浏览器我检查了登录按钮的代码并找到了:

< div class =“submit submit_buttons form-row”>  < a class =“btn-blue”title =“登录我的帐户的按钮”href =“javascript:void(0)”>登录  < / DIV>

非常感谢任何帮助!

米克

请注意,此问题是与之前与网站WebBrowser website timeout相关的问题的后续问题 成功回答了。

1 个答案:

答案 0 :(得分:1)

找到那样的按钮

HtmlElementCollection elements = webBrowser1.Document.GetElementsByTagName("a");
//this vill take elements tagget with <a></a>

然后发送点击

//first find your submit button in <a> tags with the tags diffrence from other <a>'s
//on your code it seem your tags title difrent than other <a>'s 
HtmlElement yourTag;
foreach(HtmlElement o in elements)
{
    if(o.GetAttribute("title")=="Button to Login to My Account")
    {
        yourTag=o;
    }
}
yourTag.InvokeMember("click");

或者您可以找到具有任何不同属性的按钮 这应该工作

如果您的标签与其他标签没有任何差异,您可以找到div包含它的class属性并访问其子节点并发送单击

myHtmlElement.Children[index].InvokeMember("click");
相关问题