简体   繁体   English

如何使用Selenium WebDriver处理Excel下载弹出窗口

[英]How to handle Excel download popup using Selenium WebDriver

  • How to handle Excel download popup using Selenium WebDriver 如何使用Selenium WebDriver处理Excel下载弹出窗口

Excel下载弹出

You must create/modify the browser profile to auto download/save the excel file which happens on pop up (or) can use Robot class to handle window pop ups. 您必须创建/修改浏览器配置文件才能自动下载/保存在弹出窗口中发生的excel文件(或可以使用Robot类处理窗口弹出窗口)。

Refer How to download any file and save it to the desired location using Selenium Webdriver 请参阅如何使用Selenium Webdriver下载任何文件并将其保存到所需位置

I think you are looking for something like this 我想你正在寻找这样的东西

//common to all the cases
FirefoxProfile prof = new FirefoxProfile();

//Case:1 - Use this case to set download this code to your browser's default location
//prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
//prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");

//Case:2 - Download file to Desktop
//prof.setPreference("browser.download.folderList", 0);
//prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");
//prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");


//Case:3 - Download to custom folder path. Replace d:\\selenium with your Download Location 
prof.setPreference("browser.download.dir","D:\\selenium\\");
prof.setPreference("browser.download.folderList", 2);
prof.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/zip");


//Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.

prof.setPreference("browser.helperApps.neverAsk.saveToDisk", 
    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;"//MIME types Of MS Excel File.
    + "application/pdf;" //MIME types Of PDF File.
    + "application/vnd.openxmlformats-officedocument.wordprocessingml.document;" //MIME types Of MS doc File.
    + "text/plain;" //MIME types Of text File.
    + "text/csv"); //MIME types Of CSV File.

//This will work for all cases mentioned above
WebDriver driver = new FirefoxDriver(prof);
driver.get("http://docs.seleniumhq.org/download/");
driver.findElement(By.xpath("//tr[1]/td[4]/a[text()='Download']")).click();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Selenium Webdriver下载excel时如何处理firefox中的下载弹出窗口 - How to handle download pop-up in firefox, while downloading excel using Selenium Webdriver 如何使用 Selenium Webdriver 处理浏览器身份验证弹出窗口 - How to Handle Browser Authentication popup using Selenium Webdriver 如何使用python处理Selenium WebDriver的身份验证弹出窗口? - How to handle authentication popup with Selenium WebDriver using python? 如何使用带有Java的Selenium WebDriver处理日历弹出窗口? - How to handle calendar popup using Selenium WebDriver with Java? 如何使用Java通过Selenium WebDriver处理fancybox弹出窗口 - How to handle fancybox popup through Selenium WebDriver using Java 如何使用Selenium WebDriver处理“使用Google登录”弹出窗口 - How to handle 'Log in with Google' popup window using Selenium WebDriver 如何使用Selenium WebDriver处理叠加/弹出窗口 - How to handle overlay/popup window using selenium webdriver 如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口 - How to handle authentication popup with Selenium WebDriver using Java 如何使用 Java 使用 Selenium WebDriver 在 Chrome 中处理身份验证弹出窗口 - How to handle authentication popup in Chrome with Selenium WebDriver using Java 如何在Selenium2(Webdriver)中处理POPUP浏览器? - How to Handle POPUP browser in Selenium2(Webdriver)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM