InvokeMember(“点击”)于WebBrowser控件(InvokeMember(“clic

2019-08-22 00:29发布

一个网站显示基于表选项可供选择。 HTML

<td width="33%" class="cont"><input type="radio" name="gatewayIDV" onclick="setBank(11,0,1)">
<td width="33%" class="cont"><input type="radio" name="gatewayIDV" onclick="setBank(3,0,1)">

我想调用字符串“setBank(11,0,1)”的无线电的点击。 我如何能? 所有无线电名是相同的,但onclick()的参数是不同的。

在JavaScript中有人这样做了一些代码在这里,但我怎么做这在C#

我尝试这一点,但从未工作:

if (webBrowser1.DocumentText.IndexOf("setBank(11,0,1)", StringComparison.InvariantCultureIgnoreCase) > 1)
{
    webBrowser1.Document.GetElementById("gatewayIDV").InvokeMember("click");
}

JavaScript的

$("td.cont").each(function(index) {
        var $this = $(this);
        var gonext = true;
        if($this.html().search(searchStr) != -1) {
            $(document).BookingEngine("setAutomationRunningStatus",
                  !tabData.automationRunning);
            console.log(index+":"+$this.html()+":");
            $this.children("input[name='gatewayIDV']").click();
            gonext = false;
        }
        return gonext;
    });

Answer 1:

你必须多单选按钮,输入您必须通过他们循环,试试这个:

 private void Form1_Load_1(object sender, EventArgs e)
        {
            webBrowser1.Navigate("url");
        }


        private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input"))
            {
                if (el.Name == "gatewayIDV")
                {
                    el.InvokeMember("Click");
                }
            }
        }

编辑

对于具体的单选按钮

 private void Form1_Load_1(object sender, EventArgs e)
    {
        webBrowser1.Navigate(@"E:\Documents and Settings\Ali\Desktop\ww.html");
    }


    private void webBrowser1_DocumentCompleted_1(object sender, WebBrowserDocumentCompletedEventArgs e)
    {
        foreach (HtmlElement el in webBrowser1.Document.GetElementsByTagName("input"))
        {
            if (el.Name == "gatewayIDV" && el.OuterHtml.Contains("setBank(11,0,1)"))
            {
                el.InvokeMember("Click");
            }
        }
    }


文章来源: InvokeMember(“click”) in WebBrowser control