WebBrowser control - Get element By type?

做~自己de王妃 提交于 2019-11-29 11:32:01

You can use GetElementsByTagName.

var elements = m_Browser.Document.GetElementsByTagName("button");
foreach (HtmlElement element in elements)
{
     // If there's more than one button, you can check the
     //element.InnerHTML to see if it's the one you want
     if (element.InnerHTML.Contains("Send Invitations"))
     {
          element.InvokeMember("click");
     }
}

i have tried the following code, and was successfull.

HtmlElementCollection htmlcol = ((WebBrowser)sender).Document.GetElementsByTagName("input");
for (int i = 0; i < htmlcol.Count; i++)
            {
                if (htmlcol[i].GetAttribute("value") == "Search")
                {
                    htmlcol[i].InvokeMember("click");
                }
            }

i have tried this code for the following condition

<input type="submit" value="Search">

you can also try for such html tags and i am hopeful that it will work for you... enjoy

Well a button with no id or name like that will submit whatever form it is contained within - if you know the HTML, then does the form have an id? If so you can find the form by it's id and call it's submit method.

In fact you would probably be better to find out all the fields of that form and then just POST to it yourself:

var inputs = new NameValueCollection();
inputs.Add("field1", "value1");
inputs.Add("field2", "value2");
inputs.Add("field3", "value3");

System.Net.WebClient Client = new WebClient();
Client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
byte[] POSTResultData = Client.UploadValues(postUrl, inputs);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!