Unable to download PDF document from Edge Chromium browser

Hi All,

I am trying to download a pdf document from MS Edge Chromium browser on a click of a button. I have configured the Desired Capabilities in Katalon settings as below. But still file is not getting download.
Glad if someone can help me on this.

Thanks!

To resolve the PDF download issue in Microsoft Edge Chromium with Katalon Studio, configure these browser options and capabilities:

1. Essential Edge Options for PDF Downloads

groovy

import org.openqa.selenium.PageLoadStrategy
import org.openqa.selenium.edge.EdgeOptions
import com.kms.katalon.core.webui.driver.DriverFactory

// Set download directory (use absolute path)
String downloadDir = "C:\\Your\\Download\\Path"

EdgeOptions edgeOptions = new EdgeOptions().tap {
    // Browser settings
    setPageLoadStrategy(PageLoadStrategy.NORMAL)
    addArguments("--start-maximized")
    addArguments("--disable-notifications")
    addArguments("--disable-extensions")
    
    // PDF download preferences
    Map<String, Object> prefs = new HashMap<>()
    prefs.put("download.default_directory", downloadDir)
    prefs.put("download.prompt_for_download", false)
    prefs.put("plugins.always_open_pdf_externally", true) // Critical for PDFs
    prefs.put("safebrowsing.enabled", true)
    
    // Set preferences
    setExperimentalOption("prefs", prefs)
}

// Apply options when starting browser
WebUI.openBrowser(
    "",
    [],
    edgeOptions,
    DriverFactory.getWebDriverPreferences()
)

2. Required Capabilities in Katalon Settings

Add these to your execution.properties:

text

# Edge-specific capabilities
edgeOptions.args=["--start-maximized", "--disable-notifications"]
edgeOptions.prefs={"download.default_directory":"C:\\Your\\Download\\Path", "download.prompt_for_download":false, "plugins.always_open_pdf_externally":true}
edgeOptions.experimentalOption={"prefs": {"download.default_directory":"C:\\Your\\Download\\Path","download.prompt_for_download":false}}

3. Additional Verification Steps

  1. Ensure the download directory:
  • Already exists
  • Has write permissions
  • Path uses double backslashes (C:\\Downloads)
  1. Add these steps after clicking download:

groovy

// Wait for download to complete
WebUI.delay(10)

// Verify file exists
File downloadedFile = new File("$downloadDir\\yourfile.pdf")
assert downloadedFile.exists() : "PDF download failed"

4. Common Fixes for Edge-Specific Issues

  • EdgeDriver Compatibility:
  • PDF Viewer Policy:
    Add this browser argument to force downloads:

groovy

edgeOptions.addArguments("--force-pdf-download")
  • Network Configuration:
    Disable Edge’s built-in PDF viewer completely:

groovy

edgeOptions.addArguments("--disable-pdf-plugin")

Troubleshooting Tips:

  1. Check Edge’s internal PDF viewer status:

groovy

WebUI.executeJavaScript("return navigator.plugins[0].filename", null)
// Should return "internal-pdf-viewer"
  1. Add download verification logic:

groovy

int timeout = 30
while (timeout > 0) {
    if (new File("$downloadDir\\yourfile.pdf").exists()) break
    WebUI.delay(1)
    timeout--
}
assert timeout > 0 : "Download timed out"
  1. If using Test Case/Suite hooks:

groovy

@BeforeTestCase
def setupEdgeDownloads() {
    // Apply the same Edge options here
}

Note: Edge requires absolute paths for download directories. The plugins.always_open_pdf_externally preference is crucial for triggering downloads instead of browser previews. Monitor Edge’s download manager page (edge://downloads/) during execution for debugging.

I have following questions:

  1. Where I need to add the code under groovy? Do I have to create a keyword and call it?
  2. Required Capabilities in Katalon Settings. Do I have to add the code in Desired Capabilities or execution.properities file in folder path\settings\internal folder?

@Thushar, make sure the download.default_directory is correctly set in the Edge options under Desired Capabilities and that download.prompt_for_download is disabled. Also, ensure Edge has permissions to download automatically without asking. You may need to use EdgeOptions with prefs instead of plain Desired Capabilities in Katalon. Try switching to WebDriver scripting for more control if needed.

Hey @infodessertbar, welcome to the Katalon Community! Awesome to see your first post here! :waving_hand: We’re super excited to have you join us ^^.