如何在Selenium中移动鼠标?

我试图在随机曲线或抛物线上模拟鼠标移动,因此看起来鼠标实际上在页面上移动.使用Selenium,我只知道如何点击某个元素,但这并不能模拟某些网站上的真实用户.我希望鼠标沿着我计算的随机线移动,然后单击该元素. 最佳答案 使用Selenium Webdriver,您可以使用“Actions”来执行此操作.让我们说webDriver是你的selenium驱动程序的实例,这里是
Java中的一段代码:

    Actions action = new Actions(webDriver);

    // First, go to your start point or Element
    action.moveToElement(startElement);
    action.perform();

    // Then, move the mouse
    action.moveByOffset(x,y);
    action.perform();

    // Then, move again (you can implement your one code to follow your curve...)
    action.moveByOffset(x2,y2);
    action.perform();

    // Finaly, click
    action.click();
    action.perform();

您可以参考此网址以获取所有可能的操作(双击,按住…)
http://selenium.googlecode.com/git/docs/api/java/org/openqa/selenium/interactions/Actions.html

点赞