[转]webBrowser通过name寻找控件并赋值

//防止页面多次刷新页面执行
            if (num == 1)
            {
                string GetUserName = System.Configuration.ConfigurationSettings.AppSettings["Y2000UserName"].ToString();
                string GetUserPassword = System.Configuration.ConfigurationSettings.AppSettings["Y2000UserPassword"].ToString();
                int a = 1;
                int all = webBrowser1.Document.Body.All.Count;

                for (int i = 0; i < all; i++)
                {
                    HtmlElement GetElement = webBrowser1.Document.All[i];
                    //取到包含input标签的元素
                    if (GetElement.TagName.ToUpper().ToString() == "INPUT")
                    {
                        //根据input的Name属性,找到该元素并赋值:给用户名输入框赋值
                        if (GetElement.Name.ToString() == "UserName")
                        {
                            webBrowser1.Document.All[i].SetAttribute("value", GetUserName);
                        }
                        //根据input的Name属性,找到该元素并赋值:给密码输入框赋值
                        if (GetElement.Name.ToString() == "Passwd")
                        {
                            webBrowser1.Document.All[i].SetAttribute("value", GetUserPassword);
                        }
                    }

                    //根据input的Name属性,找到提交按钮并执行动作
                    if (GetElement.Name.ToString() == "Submit")
                    {
                        //过滤点击页面中相同"name=Submit"的元素
                        if (a == 1)
                        {
                            webBrowser1.Document.All[i].InvokeMember("click");
                        }
                        a++;
                    }
                }
                num++;
            }

 

转载于:https://www.cnblogs.com/eagereagle/archive/2011/11/25/2262624.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值