Click an HTML link inside a WebBrowser Control

Something like this should work:

HtmlElement link = webBrowser.Document.GetElementByID("u_lp_id_58547")
link.InvokeMember("Click")

EDIT:

Since the IDs are generated randomly, another option may be to identify the links by their InnerText; along these lines.

HtmlElementCollection links = webBrowser.Document.GetElementsByTagName("A");

foreach (HtmlElement link in links)
{
    if (link.InnerText.Equals("My Assigned"))
        link.InvokeMember("Click");
}

UPDATE:

You can get the links within an IFrame using:

webBrowser.Document.Window.Frames["MyIFrame"].Document.GetElementsByTagName("A");

Leave a Comment