WebBrowser控件中的InvokeMember(“单击”)

时间:2013-04-11 17:05:31

标签: c# javascript winforms webbrowser-control invokemember

网站显示了一个基于表格的选项供您选择。 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;
    });

1 个答案:

答案 0 :(得分:2)

你有多个单选按钮输入,你必须循环它们,试试这个:

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