WebBrowser control - Get element By type?

后端 未结 3 1099
长情又很酷
长情又很酷 2020-12-19 15:49

I need to get a element by type in C# the HTML looks like this:




        
相关标签:
3条回答
  • 2020-12-19 16:14

    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);
    
    0 讨论(0)
  • 2020-12-19 16:20

    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");
         }
    }
    
    0 讨论(0)
  • 2020-12-19 16:22

    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

    0 讨论(0)
提交回复
热议问题