I searched the internet and found examples for;
我在网上找了一些例子;
"How to click a button which is in a webBrowser(internet explorer) in C# ?"
如何点击c#浏览器(internet explorer)中的按钮?
And here is the code which is working on google;
这是在谷歌上工作的代码;
JS :
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
}
}
}
But my webpage button has different tags. So the program can't detect to click it.
但是我的网页按钮有不同的标签。所以程序无法检测到点击它。
My main question is; How to click this button programmatically ?
我的主要问题是;如何以编程方式单击此按钮?
HTML :
HTML:
<a class="orderContinue" href="Addresses" title="Sipar Ver">Sipar Devam</a>
2 个解决方案
#1
8
Naturally the code you've posted won't find the tag you've posted. It's looking for tags of type input
:
当然,您所发布的代码不会找到您所发布的标记。它在寻找输入类型的标签:
webBrowser1.Document.GetElementsByTagName("input")
But as you say (and demonstrate):
但正如你所说(和演示):
But my webpage button has different tags.
但是我的网页按钮有不同的标签。
Thus, you need to look for the tag(s) that you use. Something like this:
因此,您需要查找您使用的标记。是这样的:
webBrowser1.Document.GetElementsByTagName("a")
This would return the anchor elements within the document. Then, naturally, you need to find the specific one(s) you want to click. That's what this line is doing:
这将返回文档中的锚元素。然后,自然地,你需要找到你想要点击的那个。这就是这条线的作用:
if (element.GetAttribute(attribute).Equals(attName))
Whether it finds the target tag(s) depends entirely on the values for those variables, which I assume you know and can manage.
它是否找到目标标记完全取决于这些变量的值,我假设您知道并且能够管理这些变量。
#2
-1
Using jQuery, you could put a click event on that a tag.
You would want to place this code at the bottom of your page
使用jQuery,您可以在标签上放置一个单击事件。您可能希望将此代码放在页面的底部
<script>
$(document).ready(function() {
$('.orderContinue').click(function() {
alert('Sipar Ver has been clicked');
// More jQuery code...
});
});
</script>
#1
8
Naturally the code you've posted won't find the tag you've posted. It's looking for tags of type input
:
当然,您所发布的代码不会找到您所发布的标记。它在寻找输入类型的标签:
webBrowser1.Document.GetElementsByTagName("input")
But as you say (and demonstrate):
但正如你所说(和演示):
But my webpage button has different tags.
但是我的网页按钮有不同的标签。
Thus, you need to look for the tag(s) that you use. Something like this:
因此,您需要查找您使用的标记。是这样的:
webBrowser1.Document.GetElementsByTagName("a")
This would return the anchor elements within the document. Then, naturally, you need to find the specific one(s) you want to click. That's what this line is doing:
这将返回文档中的锚元素。然后,自然地,你需要找到你想要点击的那个。这就是这条线的作用:
if (element.GetAttribute(attribute).Equals(attName))
Whether it finds the target tag(s) depends entirely on the values for those variables, which I assume you know and can manage.
它是否找到目标标记完全取决于这些变量的值,我假设您知道并且能够管理这些变量。
#2
-1
Using jQuery, you could put a click event on that a tag.
You would want to place this code at the bottom of your page
使用jQuery,您可以在标签上放置一个单击事件。您可能希望将此代码放在页面的底部
<script>
$(document).ready(function() {
$('.orderContinue').click(function() {
alert('Sipar Ver has been clicked');
// More jQuery code...
});
});
</script>