如何处理Safari Web硒Webdriver的文件下载 [英] how to handle file downlaod for selenium webdriver for safari
本文介绍了如何处理Safari Web硒Webdriver的文件下载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道Safari硒网络驱动程序具有将文件保存到特定位置的任何所需功能或选项设置,就像我们对firefox驱动程序所做的一样.
I would like to know it there is any desired capability or options setting for Safari selenium webdriver to save file to specific location Similar as we do it for firefox driver.
还希望禁用文件保存"对话框的弹出窗口.
Also want to disable the popup for file save dialog.
关于, Himanshu
Regards, Himanshu
推荐答案
您可以检查以下链接. dataDir
你工作吗,但不确定
You can check the below link. dataDir
mar do you work but not sure
http://code.google.com/p/selenium/wiki/DesiredCapabilities#Safari_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();
}
这篇关于如何处理Safari Web硒Webdriver的文件下载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文