C#如何在webBrowser1控件通過TagName,Name查
元素(沒有ID時)遍歷窗體元素
//
防止頁面多次刷新頁面執行
if (num == 1)
{
string GetUserName = System.Configuration.ConfigurationSettings.AppSettings[ " Y2000UserName "].ToString();
string GetUserPassword = System.Configuration.ConfigurationSettings.AppSettings[ " Y2000UserPassword "].ToString();
int a = 1;
int all = webBrowse東四飯店薩芬r1.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);
}1
// 根據input的Name屬性,找到提交按鈕並執行動作
if (GetElement.Name.ToString() == " Submit ")
{222222
// 過濾點擊頁面中相同"name=Submit"的元素
if (a == 1)
{
webBrowser1.Document.All[i].InvokeMember( " click ");
}
a++;
}
}
num++;
}
if (num == 1)
{
string GetUserName = System.Configuration.ConfigurationSettings.AppSettings[ " Y2000UserName "].ToString();
string GetUserPassword = System.Configuration.ConfigurationSettings.AppSettings[ " Y2000UserPassword "].ToString();
int a = 1;
int all = webBrowse東四飯店薩芬r1.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);
}1
// 根據input的Name屬性,找到提交按鈕並執行動作
if (GetElement.Name.ToString() == " Submit ")
{222222
// 過濾點擊頁面中相同"name=Submit"的元素
if (a == 1)
{
webBrowser1.Document.All[i].InvokeMember( " click ");
}
a++;
}
}
num++;
}