c# - 如何以编程方式单击按钮 - WebBrowser ( IE ) 中的按钮

标签 c# html

我在互联网上搜索并找到了例子;

“如何在 C# 中单击 webBrowser(Internet Explorer)中的按钮?”

这里的代码是 working on google ;

JS:

    void ClickButton(string attribute, string attName)
    {
        HtmlElementCollection col = webBrowser1.Document.GetElementsByTagName("input");
        foreach (HtmlElement element in col)
        {
            if (element.GetAttribute(attribute).Equals(attName))
            {
                element.InvokeMember("click");   // Invoke the "Click" member of the button
            }
        }
    }

但是我的网页按钮有不同的标签。所以程序无法检测到点击它。

我的主要问题是; 如何以编程方式点击这个按钮?

HTML:

<a class="orderContinue" href="Addresses" title="Sipar Ver">Sipar Devam</a>

最佳答案

您发布的代码自然找不到您发布的标签。它正在寻找 input 类型的标签:

webBrowser1.Document.GetElementsByTagName("input")

但正如您所说(并演示):

But my webpage button has different tags.

因此,您需要查找您使用的标签。像这样:

webBrowser1.Document.GetElementsByTagName("a")

这将返回文档中的 anchor 元素。然后,很自然地,您需要找到您要单击的特定对象。这就是这条线正在做的事情:

if (element.GetAttribute(attribute).Equals(attName))

它是否找到目标标签完全取决于这些变量的值,我假设您知道并且可以管理这些值。

关于c# - 如何以编程方式单击按钮 - WebBrowser ( IE ) 中的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8987983/

相关文章:

c# - 使用 C# 在时间表/日历上显示类次

c# - 在不保存远程文件的情况下测量互联网速度

c# - HttpClient 在 using 语句中

javascript - 使用 javascript/Jquery 动态创建一个 Div

javascript - 更改 url 结尾以反射(reflect)当前月份的脚本 Ex 04/01/2019

java - 如何从 JSPX 输出 <option selected ="true">?

c# - ASP.NET : I wanted to know how to insert '\n' on the label

c# - 在 C# 中根据索引值替换字节

python - BeautifulSoup 4 : Dealing with urls containing <br/>

javascript - 如何让子 div 用边距填充父 div 的空间?