您的位置:首页 > 编程语言 > C#

C#:webBrowser1控件通过TagName,Name查找元素(没有ID时)

2010-05-19 17:13 561 查看
        
 云南特产健康论坛创业论坛淘宝客低空飞行网页目录 
        
//防止页面多次刷新页面执行

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++;

}

        
 云南特产健康论坛创业论坛淘宝客低空飞行网页目录 
        
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: