如何使用机器人类在Selenium中基于web元素而不是getlocation的xy坐标执行mousemove?

问题陈述:如何在Selenium中使用机器人类基于webelement而不是getlocation的xy坐标执行鼠标移动?

下面的代码段通常用于鼠标移动,该鼠标基于x-y坐标移动鼠标

 Robot robot = new Robot();
 robot.mouseMove(to_x,to_y); 

但是,有没有一种方法可以基于Web元素移动机器人类的鼠标而不使用getlocation?

Example:
    webelement drag = driver.findelement(by_xpath('xpaht'))
    Robot robot = new Robot();
    robot.mouseMove(drag); //Is there any way to do it like this in selenium java

我不想使用动作元素的movetoelement。

硒3.141 / Java Chromedriver 76和FF浏览器

GoDolphinboy 回答:如何使用机器人类在Selenium中基于web元素而不是getlocation的xy坐标执行mousemove?

您可以使用Locatable类-

Locatable hoverItem = (Locatable) driver.findElement(By.xpath("element xpath"));enter code here
int y = hoverItem.getCoordinates().getLocationOnScreen().getY();
((JavascriptExecutor)driver).executeScript("window.scrollBy(0,"+y+");");

希望获得帮助。

本文链接:https://www.f2er.com/3137954.html

大家都在问