Reputation: 35933
Context
I am implementing Selenium WebDriver tests using NUnit in C#. All works and this question is not about how to simulate the mouse pointer movements with Selenium and within the browser. I noticed when the test is running and the browser window appears, in some cases when the real mouse pointer left randomly over the page on sensitive point it interferes the virtual mouse simulations executed by the code.
I hope that physically position out the physical mouse pointer over the browser (say 0,0) and I will position the browser not to be there will prevent this issue. The Selenium WebDriver mouse operations does not play, as they do not move the physical pointer, and especially not outside of the browser window
Question
Bottom line, I need to position the mouse in a class lib dll (unit test) where there is no WPF or WinForms. The task is completely independent of Selenium, just wanted to proactively answer the "why would you do that" questions
Upvotes: 0
Views: 242
Reputation:
You could use PInvoke, so you dont need any framework:
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
Please notice you'll need this:
using System.Runtime.InteropServices;
See here: http://www.pinvoke.net/default.aspx/user32.setcursorpos
Have Fun!
Upvotes: 3