'C# equivalent to Java Robot class

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.



Solution 1:[1]

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.

  • The other alternative is the Global Mouse and Keyboard Library which uses the Global Hooks which can capture mouse and keyboard events from any application. These events are very similar to the ones that appear on Windows controls.

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.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 undetected Selenium