如何使用webbrowser winforms控件单击ng-click

时间:2017-02-15 18:22:00

标签: c# webbrowser-control

我有一个连接到网站的WebBrowser控件,并解析html以对其进行操作。

我发现了这个标签:

 <div class="col-xs-6 col-sm-2 col-md-2 grid_row grid_row_border_left grid_col_select ng-binding" ng-click="vmFASummary.navigateToDetails(summaryRow)" tabindex="0">01/2017</div>

我需要点击ng-click点击进入下一页。

我尝试过这些代码片段无济于事。

    MethodInfo clickMethod = wbrElm.GetType().GetMethod("ng-click");
    clickMethod.Invoke(wbrElm, null);
    -----------------------------------------------
    webBrowser1.DocumentCompleted += (s, e) =>
     {  
      webBrowser1.Document.InvokeScript("vmFASummary.navigateToDetails", new object[] { true });
     };
   ------------------------------------------------

   System.Windows.Forms.Application.DoEvents();
   wbrElm.Document.InvokeScript("vmFASummary.navigateToDetails", new String[] { "summaryRow" });
   -----------------------------------------------
   wbrElm.RaiseEvent("ng-click");
   -----------------------------------------------
   wbrElm.InvokeMember("click");

1 个答案:

答案 0 :(得分:1)

尝试这样的事情:

var links = webBrowser1.Document.GetElementsByTagName("div");
                foreach (HtmlElement link in links)
                {  
                    if(link !=null)
                    {

                        if (link.GetAttribute("ng-click").Equals("vmFASummary.navigateToDetails(summaryRow)"))
                        {

                            link.InvokeMember("Click");
                        }  
                    }
                }