How do you click a button in a webbrowser control?

webBrowser1.Navigate("http://www.google.com");

If you have an ID use this:

webBrowser1.Document.GetElementById("id").InvokeMember("click");

If you have TagName use this

 webBrowser1.Navigate("http://www.google.com");

In Web Browser DocumentCompleted event

HtmlElement textElement = webBrowser1.Document.All.GetElementsByName("q")[0];
textElement.SetAttribute("value", "your text to search");
HtmlElement btnElement = webBrowser1.Document.All.GetElementsByName("btnG")[0];
btnElement.InvokeMember("click");

If you have name Class use this:

HtmlElementCollection classButton = webBrowser1.Document.All;
foreach (HtmlElement element in classButton) 
{
    if (element.GetAttribute("className") == "button")
    {
        element.InvokeMember("click");
    }
}

For adding text in a TextBox to search google.com, use this:

 webBrowser1.Document.GetElementById("gs_tti0").InnerText = "hello world";

Leave a Comment