我想知道的是,Safari selenium webdriver是否有任何所需的功能或选项设置来将文件保存到特定位置,就像我们对firefox驱动程序所做的那样。
还想禁用弹出的文件保存对话框。
你好,喜曼殊
发布于 2014-01-09 12:18:22
您可以检查下面的链接。dataDir mar你工作但不确定
specific
尝尝这个
Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);
CommandExecutor executor = new SeleneseCommandExecutor(sel);
DesiredCapabilities dc = new DesiredCapabilities();
dc.setCapability("safari.options.dataDir", "your folder path");
WebDriver browser = new RemoteWebDriver(executor, dc);新更新:关闭保存下载警告
WebElement link = driver.findElement(By.xpath("myxpath"));
clickAndSaveFileIE(link);
public static void clickAndSaveFileIE(WebElement element) throws InterruptedException{
try {
Robot robot = new Robot();
//get the focus on the element..don't use click since it stalls the driver
element.sendKeys("");
//simulate pressing enter
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
//wait for the modal dialog to open
Thread.sleep(2000);
//press s key to save
robot.keyPress(KeyEvent.VK_S);
robot.keyRelease(KeyEvent.VK_S);
Thread.sleep(2000);
//press enter to save the file with default name and in default location
robot.keyPress(KeyEvent.VK_ENTER);
robot.keyRelease(KeyEvent.VK_ENTER);
} catch (AWTException e) {
e.printStackTrace();
}https://stackoverflow.com/questions/21018253
复制相似问题