【问题标题】:How to Invoke Click on this Button in WebBrowser如何在 WebBrowser 中调用单击此按钮
【发布时间】:2017-11-13 20:19:28
【问题描述】:

这是 HTML 按钮...

<div class="submitBtnContainer">

<button class="nf-btn nf-btn-primary nf-btn-solid nf-btn-align-undefined nf-btn-oversize" type="button" autocomplete="off" tabindex="0" placeholder="planSelection_button_continue"><!-- react-text: 186 -->CONTINUE<!-- /react-text --></button>

</div>

我正在尝试这段代码...

For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
If Element.OuterHtml.Contains("submitBtnContainer") Then
Element.InvokeMember("click")
Return
End If
Next

【问题讨论】:

    标签: html vb.net button webbrowser-control


    【解决方案1】:

    您正在请求作为锚标记的标记“a”的元素。据我所知,没有锚标签(URL 链接)。我建议您将“a”替换为“button”,这是按钮本身的标签。

    【讨论】:

    • 不幸的是...不工作... :/ WebBrowser 上的按钮是蓝色的,但在 Google Chrome 中是红色的,我不知道这是否重要。
    【解决方案2】:

    您必须单击按钮本身,不能单击任何其他元素并期望它起作用。当前,您正在尝试单击 &lt;a&gt;(锚点)元素,也称为链接。

    迭代所有&lt;button&gt;标签并检查它们的文本。

    For Each Element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("button")
        If Element.InnerText = "CONTINUE" Then
            Element.InvokeMember("click")
            Exit For 'Stop looping.
        End If
    Next
    

    【讨论】:

      猜你喜欢
      • 2014-02-16
      • 2014-12-11
      • 1970-01-01
      • 2012-07-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多