我正在尝试使用 selenium 将 .html 页面保存到我的桌面中。
有人可以帮忙吗?
最佳答案
您可以使用Advanced User Interactions API :
new Actions(driver)
.sendKeys(Keys.chord(Keys.CONTROL, "s"))
.perform();
这将打开“另存为”对话框,然后您需要在其中手动导航/使用 Java 的 Robot
类:
Robot robot = new Robot();
// press Ctrl+S the Robot's way
robot.keyPress(KeyEvent.VK_CONTROL);
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_CONTROL);
robot.keyRelease(KeyEvent.VK_S);
// press Enter
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
按 Ctrl+S、Enter。请注意,这并不适用于所有系统和/或浏览器。
关于java - 如何使用 Selenium webdriver 执行 Control + Save 操作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17716061/