![[转载]C#如何在webBrowser1控件通过TagName,Name查找元素(没有ID时)遍历窗体元素 [转载]C#如何在webBrowser1控件通过TagName,Name查找元素(没有ID时)遍历窗体元素](https://image.shishitao.com:8440/aHR0cHM6Ly9ia3FzaW1nLmlrYWZhbi5jb20vdXBsb2FkL2NoYXRncHQtcy5wbmc%2FIQ%3D%3D.png?!?w=700&webp=1)
//防止页面多次刷新页面执行 if (num == ) { string GetUserName = System.Configuration.ConfigurationSettings.AppSettings["Y2000UserName"].ToString(); string GetUserPassword = System.Configuration.ConfigurationSettings.AppSettings["Y2000UserPassword"].ToString(); int a = ; int all = webBrowse东四饭店萨芬r1.Document.Body.All.Count; for (int i = ; 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 == ) { webBrowser1.Document.All[i].InvokeMember("click"); } a++; } } num++; }