使用网页浏览器点击一个按钮在网页中 [英] Using webbrowser to click on a button in a webpage

查看:231
本文介绍了使用网页浏览器点击一个按钮在网页中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我需要做的就是用这个code:

so what I need to do is to use this code:

WebBrowser browser = new WebBrowser();
browser.Navigate("www.somthing.com");
browser.Document.GetElementById("ID").InvokeMember("click");

然后我需要找到在页面的按钮的ID,并把我的code,但我的问题是一些按钮没有标识的!我该怎么办呢?他们只有类型和类和其他一些东西,但没有编号。我意识到,有些按钮可能是java,也许这就是为什么我不能在上面点击由通常的方式。所以你知道我应该怎么办?

and then i need to find the id of the button in the page and put in my code but my problem is some of the buttons don't have Id's! what should I do then? they only have type and class and some other things but no Id. i realized that some buttons might be java and maybe that's why i can't click on them by the usual way. so do you know what should I do?

推荐答案

您说您的按钮元素有一个的className ,你可以这样得到这个元素:

You said your button element has a className ,you can get this element with like this:

public Form1()
        {
            InitializeComponent();
            webBrowser1.Navigate("To your register account url");
        }
        int on = 0;
        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            foreach (HtmlElement btn in webBrowser1.Document.GetElementsByTagName("button"))
            {
                if (btn.GetAttribute("className") == "yourclassname")
                {
                    btn.InvokeMember("Click");
                    break;
                }
            }
        }

这篇关于使用网页浏览器点击一个按钮在网页中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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