用c#自动点击按钮

时间:2011-12-25 18:08:17

标签: c# facebook webbrowser-control

我的目标是分别点击像按钮这样的Facebook,但代码不起作用,但都失败了。

    IEnumerator enumerator = null;
    IEnumerator enumerator2 = null;
    HtmlElementCollection all = this.WebBrowser1.Document.All;
    try {
        enumerator = all.GetEnumerator;
        while (enumerator.MoveNext()) {
            HtmlElement current = (HtmlElement)enumerator.Current;
            if ((current.GetAttribute("name") == "like")) {
                current.InvokeMember("click");
            }
        }
    } finally {
        if (enumerator is IDisposable) {
            (enumerator as IDisposable).Dispose();
        }
    }

错误代码

Error 1 Cannot convert method group 'GetEnumerator' to non-delegate type 'System.Collections.IEnumerator'. Did you intend to invoke the method? C:\Users\S'rchade\AppData\Local\Temporary Projects\FriendFeeder\Form1.cs 37 30 FriendFeeder giving this

2 个答案:

答案 0 :(得分:0)

你可以实现这个

For Each abc As System.Windows.Forms.HtmlWindow In WebBrowser1.Document.Window.Frames
            For Each html As System.Windows.Forms.HtmlElement In WebBrowser1.Document.GetElementsByTagName("a")
                If html.InnerText = "" Then
                    html.InvokeMember("click")
                End If
            Next
Next

答案 1 :(得分:0)

此功能将返回页面中的所有Like按钮,自行完成剩下的工作!

    static IEnumerable<HtmlElement> LikeButtons(HtmlDocument doc)
    {
        foreach (HtmlElement e in from HtmlElement e in doc.All where e.GetAttribute("className") == "default_message" &&  e.InnerText =="Like" select e)
            yield return e;
    }