在一个WebBrowser控件执行点击 [英] Perform a click on a Webbrowser control

查看:239
本文介绍了在一个WebBrowser控件执行点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道上执行控制点击一个网页浏览器内的一个好办法吗? $ P从ID pferably $?

Does anybody know a good way to perform a click on a control inside of a webbrowser? Preferably from ID?

谢谢,所有的建议都是AP preciated。

Thanks, ALL suggestions are appreciated.

推荐答案

使用的HtmlElement.InvokeMember(点击)方法。下面是一个使用谷歌我觉得很幸运样本表单按钮:

Use the HtmlElement.InvokeMember("click") method. Here's a sample form that uses the Google "I feel lucky" button:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        webBrowser1.Url = new Uri("http://google.com");
        webBrowser1.DocumentCompleted += webBrowser1_DocumentCompleted;
    }

    void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) {
        if (webBrowser1.Url.Host.EndsWith("google.com")) {
            HtmlDocument doc = webBrowser1.Document;
            HtmlElement ask = doc.All["q"];
            HtmlElement lucky = doc.All["btnI"];
            ask.InnerText = "stackoverflow";
            lucky.InvokeMember("click");
        }
    }
}

这篇关于在一个WebBrowser控件执行点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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