0

I am testing the DotNetBrowser and can't find the way simulate mouse move and mouse click. Is it possible to do without using JavaScript but just methods of the component?

It must work on Flash elements in the page. So simulation click and move via JavaScript won't help.

Or maybe there is a way to simulate a click on WPF control?

user3763845
  • 95
  • 14

2 Answers2

2

According to the documentation it should be quite simple to simulate a click.

using DotNetBrowser;
using DotNetBrowser.DOM;
using DotNetBrowser.Events;

...

Browser browser = BrowserFactory.Create();
browser.FinishLoadingFrameEvent += delegate(object sender, FinishLoadingEventArgs e)
{
    if (e.IsMainFrame)
    {
        Browser browser = e.Browser;
        DOMDocument document = browser.GetDocument();
        DOMElement link = document.GetElementById("button");
        if (link != null)
        {
            link.Click();
        }
    }
};

browser.LoadHTML("<html><body><button id='button' " +
                 "onclick=\"alert('Button has been clicked!');\">Click Me!</button>" +
                 "</body></html>");
Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
  • Thank you for the answer! I guess it clicks via JavaScript, so it won't work on Flash. And also I need to simulate mouse move. – user3763845 Jul 25 '16 at 07:18
  • @user3763845 No it doesn't. `DOMElement` is a .Net Component of the DotNetBrowser. As you can see in the sample code, the `Click` is invoked in C# code - the JavaScript part is simply included to show that the click is working. The documentation doesn't mention anything about mouse move. If you want to manipulate Flash, this probably won't work since it's a [Plugin](http://dotnetbrowser-support.teamdev.com/documentation/adobe-flash) – Manfred Radlwimmer Jul 25 '16 at 07:22
  • Thanks again! I was using other components and they allow to simulate a click on a Flash. I think this component must have something similar as they have BrowserView that sends clicks to the Chrome when user click on the control, so I just need to simulate that clicks. – user3763845 Jul 25 '16 at 07:26
1

Currently WPF does not support simulation of the mouse movement/click in a certain position. DotNetBrowser also has no API to move the mouse.

Instead of this you can use unmanaged functions. The following post has the code sample you need: https://stackoverflow.com/a/8273118/6560605

UPDATE

We have released DotNetBrowser 1.8 which supports simulation of mouse events. You can see some examples by the next link: Simulating mouse input.

Community
  • 1
  • 1
Eugene Yakush
  • 259
  • 4
  • 6
  • thank you for the answer! I am already trying to do using the simulation of the click via Win32 API, but the problem that my browser is off-screen browser. That's why I also tried to use SendMessage with hWnd of the controller. But it looks that hidden controller can't receive Win32 Messages. Maybe you can recommend some other way how to click on the browser? Or maybe it's still possible to do via Win32 API but my code is wrong? I really like your Browser component but this option is very important for me as we use Flash on pages. I can use WinForm controller instead of WPF if it helps. – user3763845 Jul 26 '16 at 21:55