对于网页中没有id和name的按钮,可以先找到包含同样标签的元素集合,然后在该集合中按关键字符找到想找的按钮。
一般OuterHtml的全称较难找到,可以使用查找包含字符串的方式来找到按钮。
HtmlElementCollection htmlelem = webBrowser1.Document.GetElementsByTagName("input"); // for search bottom without id or name
foreach (HtmlElement item in htmlelem) // searching the bottom with name of 搜索一下
{
// if (item.OuterHtml == "<INPUT style=\"BORDER-TOP-STYLE: none; FONT-SIZE: 14px; BORDER-LEFT-STYLE: none; HEIGHT: 32px; WIDTH: 95px; BACKGROUND: url(template/image/code_button.gif); BORDER-BOTTOM-STYLE: none; BORDER-RIGHT-STYLE: none\" type=submit value=搜索一下>")
if (item.OuterHtml.Contains("value=搜索一下")) // for short
{
item.InvokeMember("click");
}
}