webbrowser获取无ID无Name控件并模拟点击

常见的获取控件并点击(自动登录):
var txtUserID = wbsTask.Document.All["userName"];
var txtPsd = wbsTask.Document.All["password"];
var txtVrf = wbsTask.Document.All["code"];var btnSubmit = wbsTask.Document.All["btnSubmit"];

var code = ReadLoginVerifyCode();
var userInfo = cboAccount.ComboBox.SelectedValue as UserInfo;
if (userInfo == null) { MessageBox.Show("获取用户信息失败!"); return; }

txtUserID.SetAttribute("value", userInfo.UserID);
txtPsd.SetAttribute("value", userInfo.Password);
txtVrf.SetAttribute("value", code);if (string.IsNullOrWhiteSpace(code)) return;
btnSubmit.InvokeMember("click");//自动提交
特殊需求:查找webbrowser页面上的一个无ID无Name的A控件,后台模拟点击件。
var b = wbsTask.Document.Body.InnerText.Contains("XXX");
if (!b) return false;
foreach (HtmlElement he in wbsTask.Document.GetElementsByTagName("a"))
{
    if (he.InnerText == "XXX")
    {
        he.InvokeMember("click");
    }
}

本文为原创文章,转载请注明出处!