【问题标题】:C# click html button with same idC#单击具有相同ID的html按钮
【发布时间】:2014-10-26 00:47:00
【问题描述】:

谁能帮帮我。 我需要知道如何使用网络浏览器自动化表单,然后单击包含“报告”文本的按钮。 我不能用 ID 来做,因为他们都有“发送”ID。

this.form.target='';
        this.form.action='/foglioorario.php';
        this.form.submit();"><OPTION value='0'></OPTION><OPTION value='1'>Tirana</OPTION></SELECT></td>
                </tr><tr>
                    <td><input name='azione' value='Importa Curva' type='button' class='TbStyle' onclick="on_click('form1', 'importForecast.php', 'import')"/></td>
                    <td colspan='2'><span style='margin-right:20px'>
                        Alpha:<input name='alpha' id='alpha' type='TEXT' maxlength='3' value='95' style='width:25px'/>% 
                        </span>  
                        <span style='margin-right:20px'>
                        TMS:<input name='tms' id='tms' type='TEXT' maxlength='3' value='290' style='width:25px'/>
                        </span>                 
                        <span>                
                        <input type='submit' id='send' name='send' value='Compara curva' class='TbStyle'/>
                        </span>
                        <span>
                        <input type='submit' id='send' name='send' value='Export CC' class='TbStyle' title='Click per export Excel'/>
                        </span>
                    </td>
                    <td><input type='submit' id='send' name='send' value='Report' class='TbStyle'/>
                    <input type='submit' id='send' name='send' value='Export R' class='TbStyle' title='Click per export Excel'/></td>
                    <td><input type='submit' id='send' name='send' value='Riepilogo Sett' class='TbStyle'/>
                    <input type='submit' id='send' name='send' value='Export S' class='TbStyle' title='Click per export Excel'/></td>
                    <td>
                        <span>Pause: <input type='checkbox' name='chkpause' /></span>
                        <span style='padding-left:10px'>Disp.Strao: <input type='checkbox' name='chkStrao' /></span>

                </tr>

【问题讨论】:

  • 您的示例中有一个奇怪的 javascript 和 html 组合,您能解释一下它是什么吗?

标签: c# html automation click send


【解决方案1】:

您的回答救了我,我只是对其进行了一些修改并在没有 mshtml 的情况下使用它。 这就是我使用它的方式:

        WebBrowser wb = webBrowser1;
        var doc = wb.Document;
        HtmlElementCollection el = doc.GetElementsByTagName("input");
        foreach (HtmlElement btn in el)
        {
            if (btn.GetAttribute("value") == "Report")
            {
                btn.InvokeMember("click");
                break;
            }
        }

你太棒了,谢谢

【讨论】:

    【解决方案2】:

    我想我明白你在说什么,如果这对你有用,请告诉我。

    IHTMLElementCollection buttonCol = doc.getElementsByTagName("input");
    foreach (IHTMLElement btn in buttonCol)
    {
        if (btn.getAttribute("value") == "Report")
        {
            btn.click();
            break;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 2020-07-25
      • 1970-01-01
      相关资源
      最近更新 更多