问题陈述:如何使用机器人类在 Selenium 中基于 webelement 而不是 getlocation 的 xy 坐标执行 mousemove?
下面的代码片段通常用于 mousemove,它根据 x-y 坐标移动鼠标
Robot robot = new Robot();
robot.mouseMove(to_x, to_y);
但是,有没有一种方法可以在不使用 getlocation 的情况下基于 webelement 移动机器人类的鼠标?
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
我不想使用 actions 类的 movetoelement。
Selenium 3.141/Java Chromedriver 76 和 FF 浏览器
最佳答案
您可以使用 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+");");
希望这有帮助。
关于java - 如何使用机器人类在 Selenium 中基于 webelement 而不是 getlocation 的 xy 坐标执行 mousemove?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58766575/