Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebBrowser control - Get element By type?

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

<button type="submit" class="orangeBtn">Send Invitations</button>

And I want it to be able to where I can invoke("click") it, but it isn't appearing to work in C#. My current code is:

HtmlElement m_SubmitField = m_Browser.Document.All["orangeBtn"];

if (m_SubmitField != null)
    m_SubmitField.InvokeMember("click");

Is there an alternative working way to do this?

This is NOT my server, so I can't edit the HTML or add jquery.

I'm making an automated application to send invites to friends that I want to join, but they made the button without a id or name as seen above, so is there anyway to have it invoke("click") in C# using a different method?

Thanks.

like image 907
Eric Avatar asked Apr 09 '11 05:04

Eric


Video Answer


1 Answers

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");
     }
}
like image 88
Michael Low Avatar answered Sep 23 '22 18:09

Michael Low