问题描述
对于鼠标指针移动,Java机器人类的C#等效项是什么?As Actions类不能直接用于键盘和鼠标.我需要在硒n c#中可视地移动鼠标指针.例如,如果我想从Rediffmail网站访问我的邮件,则鼠标指针应移至地址栏,然后移至用户名和密码文本框以及登录按钮.鼠标指针应随测试中执行的动作一起移动.
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.
推荐答案
在寻找与Java Robot类等效的C#模块时,可以有三种可能的解决方案:
As you are looking out for C# modules equivalent to Java Robot class there can be three possible solutions :
-
如果您可以调整需求表视觉上移动鼠标指针来突出显示用户名和密码文本框,您可以使用 ExecuteScript方法来自 IJavaScriptExecutor 界面,如下所示:
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);
另一种替代方法是使用 Windows输入模拟器(C#SendInput包装器-模拟键盘和鼠标)就像@ Nish26在她的评论中提到的那样.
Another alternative would be to use the Windows Input Simulator (C# SendInput Wrapper - Simulate Keyboard and Mouse) as @Nish26 mentioned in her comments.
对于第二个和第三个选项,您将找不到直接通过 WebDriver 进行交互的方式.也许您需要寻找一个量身定制的解决方案.
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.
这篇关于相当于Java Robot类的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!