模拟serche按钮单击webbrouwser c#

时间:2015-08-24 18:10:08

标签: c#

我有这个代码如何点击c#

问题1

<button onclick="SearchProducts(true);" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" role="button" aria-disabled="false"><span class="ui-button-text">
                    <i class="fa fa-search"></i>
                    Zoeken
                </span></button>

webBrowser2.Document.InvokeScript(&#34; searchbox&#34;,new object [] {true});这项工作

问题2

我有这个代码如何点击c#

<div class="searchbox" ng-click="doSubmit($event)">
  <div class="input-container">
    <form ng-submit="doSubmit($event)" class="ng-pristine ng-valid ng-valid-maxlength">
      <input type="text" maxlength="100" class="searchboxfield ng-pristine ng-untouched ng-valid ng-valid-maxlength" name="searchboxfield" data-test="searchboxfield" ng-model="searchterm" placeholder="Zoek op EAN, titel of referentiecode">
    </form>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

您应该将其作为

调用
webBrowser1.Document.InvokeScript("SearchProducts",new object[] { true });

这是一个有效的测试案例。

string html = @"<button onclick='SearchProducts(true);'>
                <script>
                function SearchProducts(bool){ alert(bool); }
                </script>";

webBrowser1.DocumentCompleted += (s, e) =>
{
    webBrowser1.Document.InvokeScript("SearchProducts",new object[] { true });
};

webBrowser1.DocumentText = html;