且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用Selenium Web驱动程序移动可见的鼠标指针?

更新时间:2023-11-22 23:41:40

这似乎很奇怪,但是如果您尝试下面的代码,将会看到,看不到正在移动的鼠标指针:

This seems very strange, but if you try the following code, you will see, that you do not see the moving mousepointer:

    PointerInput p = new PointerInput(PointerInput.Kind.MOUSE, "MyMouse");
    Interaction i = p.createPointerMove(Duration.ofSeconds(2), PointerInput.Origin.fromElement(element1), 5, 5);
    Actions builder = new Actions(driver);
    Action mouseOverHome = builder
            .tick(i).click()
            .build();
    mouseOverHome.perform();

我添加了单击以演示效果.我不得不使用//*[@id=\"nav-cart\"]上的购物车.您的xpath表达式对我不可见.单击之前,您会注意到购物车图标的鼠标悬停效果.

I added the click to demonstrate the effect. I had to work with the shopping cart at //*[@id=\"nav-cart\"]. Your xpath expression was not visible for me. You will notice the mouseover effect of the cart icon before the click.