【问题标题】:How to simulate mouse movement in selenium using java如何使用 java 在 selenium 中模拟鼠标移动
【发布时间】:2014-07-09 15:03:38
【问题描述】:

我有一个要求,当某个自动化脚本运行时,浏览器应该显示光标在脚本向前移动时从一个字段移动到另一个字段。我不确定我到底需要做什么才能完成它。我使用 Action 类来实现它,但它不起作用。

请在下面找到我实现的代码:

public void MouseHover(WebElement Mouse,WebDriver driver) throws InterruptedException
{
    Actions act = new Actions(driver);  
    act.moveToElement(Mouse).build().perform();
    System.out.println("Curser movement Performed Successfully");
}

【问题讨论】:

  • 您对操作构建器所做的就是执行鼠标悬停元素。但你真正需要的是不同的。谷歌搜索正确。

标签: java selenium-webdriver mousemove


【解决方案1】:

java.awt.Robot 类可用于以编程方式移动用户的鼠标(除其他外)。请参阅:Link

例如:
Robot r = new Robot();//construct a Robot object for default screen r.mouseMove(1360, 7);//move mouse to java coords 1360, 7 r.mousePress(InputEvent.BUTTON1_MASK);//press the left mouse button r.mouseRelease(InputEvent.BUTTON1_MASK);//release the mouse button

【讨论】:

  • 感谢您的回复。我通过链接查看,但无法理解。我对这个东西很陌生,如果你有任何相关的代码,那么你能把它贴在这里吗……如果你也贴上关于如何做的步骤,它真的会对我有帮助……
猜你喜欢
  • 1970-01-01
  • 2018-12-22
  • 2011-11-21
  • 1970-01-01
  • 2015-11-17
  • 1970-01-01
  • 2011-02-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多