Reputation: 127
What is the C# equivalent to Java Robot class for mouse pointer movements? As Actions class cannot be used directly for keyboard and mouse. I need to move my mouse pointer visually in selenium n c#. For example, if I want to access my mail from Rediffmail website, the mouse pointer should move to the address bar then to username and password textbox and log-in button. Mouse pointer should move along with the actions being performed in my tests.
Upvotes: 6
Views: 8468
Reputation: 193258
As you are looking out for C# modules equivalent to Java Robot class there can be three possible solutions :
If you can tweak your requirement form move the mouse pointer visually to highlight the username and password textbox, you can take help of ExecuteScript Method from IJavaScriptExecutor Interface as follows :
IWebElement element = driver.FindElement(By.XPath("username_field_xpath"))
((IJavaScriptExecutor)driver).ExecuteScript("arguments[0].setAttribute('style','backgroud: yellow; border: solid 2px red')", element);
Another alternative would be to use the Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse) as @Nish26 mentioned in her comments.
For the second and third options you won't find a direct way to interact through WebDriver. Perhaps you have to lookout for a tailor-made solution.
Upvotes: 4