How to simulate mouse click with the WebBrowser control

25,523

Quite easily, simply use:

button.InvokeMember("click");
Share:
25,523
The Muffin Man
Author by

The Muffin Man

I have a passion for creating data driven applications to the best of my ability. I'm currently working a lot with Angular 2 and Azure Service Fabric. Check out what I'm currently working on: http://www.easystreak.com

Updated on July 09, 2022

Comments

  • The Muffin Man
    The Muffin Man almost 2 years

    Using the WebBrowser control I am able to call an event when the mouse button is manually clicked, but I want the program to do the click itself, not do something when I manually perform the click.

    For example, if I provide the ID of a control on the page I want the program to click it.

    Here's what I have so far:

    HtmlElement button = webBrowser1.Document.GetElementById("lButtonSearch");
    button.Click += new HtmlElementEventHandler(GotoSearchPage);
    
  • Kyle Rosendo
    Kyle Rosendo about 13 years
    @Nick - Sure, no problem. If you're doing any kind of (medium->high scale) Automation, I do recommend looking at WatiN (watin.sourceforge.net). Great project.
  • The Muffin Man
    The Muffin Man about 9 years
    I looked at WatiN shortly after and have been using it ever since for many projects, thanks.