Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
907 views
in Technique[技术] by (71.8m points)

c# - InvokeMember("click") in WebBrowser control

A website shows a table based options to choose. HTML is

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

I want to Invoke click of radio of string "setBank(11,0,1)". How do I? all radio name are same but onclick() parameter is different.

in JavaScript someone does this some code are here but how I do this in c#

I try this but never work:

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;
    });
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You have multi radio button input you must loop through them,try this:

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

Edited

For specific radio button

 private void Form1_Load_1(object sender, EventArgs e)
    {
        webBrowser1.Navigate(@"E:Documents and SettingsAliDesktopww.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");
            }
        }
    }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...