using System.Windows.Forms; using mshtml; WebBrowser webBrowser1 = new WebBrowser(); webBrowser1.Navigate("https://www.example.com"); while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2; IHTMLInputElement inputElement = document.getElementById("search-box") as IHTMLInputElement; inputElement.value = "new search query";
using System.Windows.Forms; using mshtml; WebBrowser webBrowser1 = new WebBrowser(); webBrowser1.Navigate("https://www.example.com"); while (webBrowser1.ReadyState != WebBrowserReadyState.Complete) { Application.DoEvents(); } IHTMLDocument2 document = webBrowser1.Document.DomDocument as IHTMLDocument2; IHTMLElement buttonElement = document.getElementById("submit-button") as IHTMLElement; buttonElement.click();In this example, we load a webpage in a WebBrowser control, wait for it to finish loading, and access a button element with the ID "submit-button". We then simulate a button click by calling the click() method on the element. Package library: This example also uses the "mscorlib" package library that is included by default in .NET Framework.