我在互联网上搜索了一些例子;
"如何在C#中单击webBrowser(Internet Explorer)中的按钮?"
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
}
}
}
Run Code Online (Sandbox Code Playgroud)
但我的网页按钮有不同的标签.因此程序无法检测到单击它.
我的主要问题是; 如何以编程方式单击此按钮?
HTML:
<a class="orderContinue" href="Addresses" title="Sipar Ver">Sipar Devam</a>
Run Code Online (Sandbox Code Playgroud)
当然,您发布的代码无法找到您发布的代码.它正在寻找类型的标签input:
webBrowser1.Document.GetElementsByTagName("input")
Run Code Online (Sandbox Code Playgroud)
但正如你所说(并证明):
但我的网页按钮有不同的标签.
因此,您需要查找您使用的标记.像这样的东西:
webBrowser1.Document.GetElementsByTagName("a")
Run Code Online (Sandbox Code Playgroud)
这将返回文档中的锚元素.然后,您自然需要找到要单击的特定部分.这就是这条线正在做的事情:
if (element.GetAttribute(attribute).Equals(attName))
Run Code Online (Sandbox Code Playgroud)
它是否找到目标标签完全取决于这些变量的值,我假设您知道并且可以管理这些变量.