Not able to download file in chrome(59 Latest) to a specific directory without any window popup using Selenium WebDriver

后端 未结 1 1625
名媛妹妹
名媛妹妹 2020-12-12 03:25

I need to download a file in chrome browser(59 Latest Version) to a specfic directory without having window popup to show up. Using the below code it shows the window popup.

相关标签:
1条回答
  • 2020-12-12 03:55

    As I tested this functionality with Selenium 3.4.0, ChromeDriver 2.30 & Chrome 59.0, I have tried with your own code to download a excel file from the url https://www.microsoft.com/en-in/download/details.aspx?id=45485 along with some simple tweaks. The code block works fine at my end.

    System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
    String downloadFilepath = "C:\\Utility\\OP_Resources\\ChromeDownload";
    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.prompt_for_download", "false");
    chromePrefs.put("download.default_directory", downloadFilepath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);
    options.addArguments("start-maximized");
    options.addArguments("disable-infobars");
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new ChromeDriver(cap);
    driver.get("https://www.microsoft.com/en-in/download/details.aspx?id=45485");
    JavascriptExecutor jse = (JavascriptExecutor)driver;
    jse.executeScript("window.scrollBy(0,200)", "");
    driver.findElement(By.linkText("Download")).click();
    
    0 讨论(0)
提交回复
热议问题