我想使用 Java Robot 类将鼠标移到链接上以动态创建更多内容。对于 Web 交互,我使用 Selenium WebDriver。
Point coordinates = driver.findElement(By.xpath("//li[@id='1234']/a")).getLocation();
Robot robot;
try {
robot = new Robot();
robot.mouseMove(coordinates.getX(),coordinates.getY()+120);
} catch (AWTException e1) {
e1.printStackTrace();
}
Selenium 为 getLocation 函数抛出错误:
Exception in thread "main" org.openqa.selenium.WebDriverException: Cannot determine size of element
有人知道我做错了什么吗?
最佳答案
无需使用机器人即可实现鼠标悬停操作(Actions类)。
new Actions(driver).moveToElement(driver.findElement(By.xpath("//li[@id='1234']/a"))).perform();
在您的文件中包含以下导入语句。
import org.openqa.selenium.interactions.Actions;
关于java - Selenium WebDriver 和 Java 机器人类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23913197/