登录项目后,一个页面有两个框架。当我尝试使用 Robot 类移动鼠标时,鼠标不会从一个框架移动到另一个框架。我还使用了 selenium 代码将一个框架移动到另一个框架。
部分代码:
driver.switchTo().defaultContent();
driver.switchTo().frame("pageFrame");
GenerateLogFile.logger.info("Click on force auth.");
login.waitForForceAuth();
mouseMoveAction(login.forceAuth());
login.forceAuth().click();
mouseMoveAction方法:
public void mouseMoveAction(WebElement element) throws AWTException {
Point coordinates = element.getLocation();
Robot robot = new Robot();
robot.mouseMove(coordinates.getX(), coordinates.getY());
}
最佳答案
你不能混合使用Robot
和Selenium。 Selenium 已经具备了模拟鼠标事件所需的一切。最重要的是,许多 WebDrivers 不创建任何窗口(它们只是在某些内部内存区域中渲染页面),因此 Robot 没有任何东西可以使用。
在 mouseMoveAction()
中尝试以下代码:
new Actions(driver).moveToElement(element);
关于java - 当页面中存在两个框架时如何移动物理鼠标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55469219/