C# equivalent to Java Robot class

只谈情不闲聊 提交于 2020-06-15 04:18:51

问题


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.


回答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.



来源:https://stackoverflow.com/questions/49511160/c-sharp-equivalent-to-java-robot-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!