Search code examples
c#browserbuttonsimulate

c# Web Browser simulate button press


I'm using the WebBrowser control and want to bypass a button press on a web page. I'm not very familiar with HTML and web pages, but I'm wondering if anyone has a solution.

The button I'm talking about is on this web page: http://www.movshare.net/video/ut55cfdvg5wgj/?

The button is appearing at random so it might not be there always.


Solution

  • Edit: Thinking about this, you can do most of this from the C#. Updated.

    Get a reference to the button and invoke it's click() JavaScript method:

    HtmlElement btn = myBrowserControl.Document.GetElementById("myButton");
    /*
    Alternatively, take a look at these other methods for retrieving an HtmlElement:
    HtmlDocument.GetElementFromPoint(Point point)
    HtmlDocument.GetElementsByTagName(string tagName)
    HtmlDocument.All.GetElementsByName(string name)
    */
    btn.InvokeMember("click");
    

    This will only work in all browsers if ...
    Since this is a WebBrowser control, you don't need to worry about cross browser issues.