如何使用 Selenium WebDriver 处理文件下载弹出窗口? [英] How to handle file download popup using Selenium WebDriver?

查看:43
本文介绍了如何使用 Selenium WebDriver 处理文件下载弹出窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编写了一个代码来下载一个 excel 文件,它正在运行,但它在弹出窗口出现时立即停止.它应该自动下载文件并将其存储在指定位置,这现在没有发生.请任何人帮助找到解决此问题的方法

I have written a code to download an excel file, it is working, but it stops as soon as the popup appears. Automatically it should download the file and store in specified location, which is not happening now. Please anyone help in finding a solution for this problem

FirefoxProfile profile = new FirefoxProfile();
WebDriver driver = new FirefoxDriver(profile); 


profile.setPreference("browser.helperapps.neverAsk.saveToDisk" , "text/csv"); 
profile.setPreference("browser.download.folderList", 2); 
profile.setPreference("browser.download.dir","e:\SampleExcel"); 

driver.get("http://url");
driver.findElement(By.name("email")).sendKeys("abc@gmail.com");
driver.findElement(By.name("pass")).sendKeys("abc");
driver.findElement(By.id("edit-submit")).click();
driver.findElement(By.id("toolbar-link-admin-config")).click();
driver.findElement(By.linkText("Reports")).click();
driver.findElement(By.xpath("//input[@value='5']")).click();
driver.findElement(By.id("edit-submit")).click();

推荐答案

试试下面的代码

FirefoxProfile profile = new FirefoxProfile();
        String path = "D:\Downloads_sel";
        profile.setPreference("browser.download.folderList", 2);
        profile.setPreference("browser.download.dir", path);
        profile.setPreference("browser.download.alertOnEXEOpen", false);
        profile.setPreference("browser.helperApps.neverAsksaveToDisk", "application/x-msexcel,application/excel,application/x-excel,application/excel,application/x-excel,application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel");
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("browser.download.manager.focusWhenStarting", false);
        profile.setPreference("browser.helperApps.alwaysAsk.force", false);
        profile.setPreference("browser.download.manager.alertOnEXEOpen", false);
        profile.setPreference("browser.download.manager.closeWhenDone", false);
        profile.setPreference("browser.download.manager.showAlertOnComplete", false);
        profile.setPreference("browser.download.manager.useWindow", false);
        profile.setPreference("browser.download.manager.showWhenStarting", false);
        profile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
        profile.setPreference("pdfjs.disabled", true);

        WebDriver driver = new FirefoxDriver(profile);

有关完整的 MIME 类型列表,请访问以下链接:http://qaautomationworld.blogspot.in/2014/02/file-downlaoding-using-selenium.html

For complete MIME types list follow the link: http://qaautomationworld.blogspot.in/2014/02/file-downlaoding-using-selenium.html

这篇关于如何使用 Selenium WebDriver 处理文件下载弹出窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆