如何点击一个按钮编程 - 巴顿在web浏览器(IE) [英] How to Click A Button Programmatically - Button in WebBrowser ( IE )

查看:112
本文介绍了如何点击一个按钮编程 - 巴顿在web浏览器(IE)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索,发现了范例;



如何点击一个按钮,在web浏览器(Internet Explorer)中的C#?



在此可以是代码的在谷歌工作;



JS:

 无效ClickButton(字符串属性,串attName)
{
HtmlElementCollection COL = webBrowser1.Document.GetElementsByTagName(输入);
的foreach(在的HtmlElement col元素)
{
如果(element.GetAttribute(属性).Equals(attName))
{
element.InvokeMember(点击 ); //调用按钮
}
}
}


$ b的点击会员$ b

不过,我的网页按钮有不同的标签。因此该程序无法检测到点击



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



HTML:

 <一类=orderContinueHREF =地址标题=SIPAR版> SIPAR Devam< / A> 


解决方案

当然,你已经发布的代码不会找到标签您发布。它在寻找类型的变量输入

  webBrowser1.Document.GetElementsByTagName (输入)

但正如你说的(并演示):




不过,我的网页按钮有不同的标签。




因此,您需要寻找您所使用的标签(S)。事情是这样的:

  webBrowser1.Document.GetElementsByTagName(A)

这将返回文档内的锚定元件。然后,当然,你需要找到你想要点击特定的一个(S)。这就是此行是做:

 如果(element.GetAttribute(属性).Equals(attName))

无论是发现目标标记(S)完全取决于这些变量的值,我以为你知道的和可管理


I searched the internet and found examples for;

"How to click a button which is in a webBrowser(internet explorer) in C# ?"

And here is the code which is 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
            }
        }
    }

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 :

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

解决方案

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.

这篇关于如何点击一个按钮编程 - 巴顿在web浏览器(IE)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆