首页 文章

WebBrowser无法单击按钮登录网站

提问于
浏览
0

这适用于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 回答

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

相关问题