how to change file download location in Webdriver while using chrome driver/firefox driver

后端 未结 7 602
太阳男子
太阳男子 2020-11-30 07:42

I am trying to save an image by using save as option inside a specific folder. I found a way by which I am able to right click on the image which I want to save using save a

相关标签:
7条回答
  • 2020-11-30 08:30

    For Chrome Browser:

    Even you can disable the windows dialogue (Save As Dialogue) with the following code snippet. You need to do following settins in the chromedriver preferences:

    • turn off the download prompt if it appears
    • set the default directory to download the file
    • If PDF view plugin is enabled which opens the PDF file in browser, you can disable that so that download can start automatically
    • Accept any certificate in browser

      String downloadFilepath = "/path/to/download/directory/";
      Map<String, Object> preferences = new Hashtable<String, Object>();
      preferences.put("profile.default_content_settings.popups", 0);
      preferences.put("download.prompt_for_download", "false");
      preferences.put("download.default_directory", downloadFilepath);
      
      // disable flash and the PDF viewer
      preferences.put("plugins.plugins_disabled", new String[]{
          "Adobe Flash Player", "Chrome PDF Viewer"});
      
      ChromeOptions options = new ChromeOptions();
      options.setExperimentalOption("prefs", preferences);
      
      DesiredCapabilities capabilities = DesiredCapabilities.chrome();
      capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
      capabilities.setCapability(ChromeOptions.CAPABILITY, options);
      driver = new ChromeDriver(capabilities);
      
    0 讨论(0)
提交回复
热议问题