Selenium Automation一个新的窗口句柄

时间:2015-08-03 17:52:04

标签: java csv selenium

因此,在我的代码运行后,一个新窗口显示出来下载CSV。弹出一个窗口以保存文件或使用excel打开它。我如何更改窗口以使用selenium将csv下载到路径。

public class automation  {
     public static void main(String[] args) {
       FirefoxProfile profile = new FirefoxProfile();
    String path = "C:\\Users\\K344975\\Desktop";
    profile.setPreference("browser.download.dir",path);
    profile.setPreference("browser.download.manager.showWhenStarting",false);
    profile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/xls;text/csv");
    profile.setPreference("plugin.disable_full_page_plugin_for_types",
            "application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;application/xls;");
    WebDriver driver = new FirefoxDriver(profile); 

       driver.get("");
       String winHandle = driver.getWindowHandle();
       System.out.println(winHandle);

    //driver.quit();
}

}

我也试过制作个人资料

1 个答案:

答案 0 :(得分:0)

嗯,你首先修补个人资料,只有在创建浏览器之后,对于插件禁用,你可以使用

profile.setPreference("plugin.disable_full_page_plugin_for_types",
"application/octet-stream;application/csv;text/csv;application/vnd.ms-excel;")