首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何处理文件下载

如何处理文件下载
EN

Stack Overflow用户
提问于 2014-01-09 10:57:16
回答 1查看 3.3K关注 0票数 0

我想知道的是,Safari selenium webdriver是否有任何所需的功能或选项设置来将文件保存到特定位置,就像我们对firefox驱动程序所做的那样。

还想禁用弹出的文件保存对话框。

你好,喜曼殊

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-09 12:18:22

您可以检查下面的链接。dataDir mar你工作但不确定

specific

尝尝这个

代码语言:javascript
复制
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);

新更新:关闭保存下载警告

代码语言:javascript
复制
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();
        }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21018253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档