Scenario: Clicking on the button downloads the file at browser level but it is blocked and it shows as unverified download blocked. How do we handle this in katalon
If the situation is actually giving you an error, you can perhaps wrap your code in a try/catch exception. If your situation gives you a message, or some text displayed, perhaps you can use a WebUI.verifyTextPresent(“the text message”, false). The boolean parameter allows you to do direct comparison if you use “false”, or to do “Regular Expression” with wildcard etc. if you use “true”.
WebUI.verifyTextPresent(“The Save was Successful.”, false)
WebUI.verifyTextPresent(“Last Updated by ${gUserName} on ${gUpdateDate} .*”, true)
The asterisk is used to replace all characters after the date, such as the time portion.
What do you want to do? What do you mean by the word “handle”?
Do you want to avoid being blocked by a browser’s dialog when you try to download a file?
or
Do you want to assert that browser successfully block your (possibly wrong malicious) request to download a file?
Step 1: Modify Browser Settings
Adjust browser configurations to bypass download security warnings. This varies by browser:
For Chrome
-
Disable “Safe Browsing” Protection
Add these ChromeOptions before starting the driver:groovyimportorg.openqa.selenium.chrome.ChromeOptions WebDriver driver =newChromeDriver(newChromeOptions().addArguments("--safebrowsing-disable-download-protection")) -
Set Download Directory
Explicitly define where files are saved (no prompts):groovyChromeOptions chromeOptions =newChromeOptions() chromeOptions.addArguments("--disable-download-notification") Map<String, Object> prefs =newHashMap<>() prefs.put("download.default_directory", "/path/to/folder") chromeOptions.setExperimentalOption("prefs", prefs) WebDriver driver =newChromeDriver(chromeOptions)
For Firefox
-
Adjust Download Preferences
Disable certificate validation and download prompts:groovyimportorg.openqa.selenium.firefox.FirefoxOptions FirefoxOptions firefoxOptions =newFirefoxOptions() firefoxOptions.setCapability(add)"
Step 2: Avoid the Download Dialog
Some downloads trigger dialogs that Selenium cannot interact with. Workarounds:
Method 1: Use the Direct Download URL
-
Extract the Link: If the download is triggered by a clickable element, get its URL manually or via automation:
groovyString downloadLink = WebUI.getAttribute(findTestObject('object-id'), 'href') -
Download via GET Request:
groovyURL url =newURL(downloadLink) HttpURLConnection connection = url.openConnection() File file =newFile('/path/to/download') InputStreamin= connection.getInputStream() OutputStream out =newFileOutputStream(file)byte[] buffer =newbyte[1024]intbytesRead =in.read(buffer)while(bytesRead != -1) { out.write(buffer, 0, bytesRead) bytesRead =in.read(buffer) }in.close() out.close()
Method 2: Intercept the Download via RPC
For modern browsers using ChromeDriverProtocol:
groovy
driver.executeCommand('download_dense fileId beaten su 'commands... // Requires tracking the browser’s DevTools protocol
Step 3: Handle HTTP Responses
If the download is a file served via HTTP, ensure the server’s HTTPS certificate is valid or accept self-signed certificates.
Step 4: Verify Common Issues
-
HTTPS vs HTTP: Mixed content warnings? Use HTTPS for the download.
-
Outdated Browsers: Ensure Chromium-based browsers are updated (e.g., ChromeDriver).
-
Headers: If downloads require specific headers (e.g., cookies), set them via
driver.manage().window().maximize().
Final Code Example for Chrome (Simplified)
groovy
importorg.openqa.selenium.*importorg.openqa.selenium.chrome.ChromeOptionsimportorg.openqa.selenium.chrome.ChromeDriver ChromeOptions options =newChromeOptions() options.addArguments("--safebrowsing-disable-download-protection", "--disable-download-notification") Map<String, Object> prefs =newHashMap<>() prefs.put("download.default_directory", "/path/to/downloads") options.setExperimentalOption("prefs", prefs) WebDriver driver =newChromeDriver(options) driver.get("https://your-page.com/with-download") // Click button to trigger download (if the link is not accessible directly)WebUI.click(findTestObject('downloadButton')) // Find the file in /path/to/downloads // ... verification code ...driver.quit()
When to Break the Rules
Security Note: Disabling download warnings is risky for production systems. Only use this in controlled testing environments.
Hi @v.deenadayalan,
Have you solved your question yet? If yes, feel free to share with other as reference. If no, we would love to hearing back from you. Thank you
Hi @v.deenadayalan,
Have you solved your issue? Can we close this topic?