How to handle browser popup in Katalon?

Hi there,

Actually I want to save a pdf file using Firefox but to do this, Firefox generate a browser/system popup and it is not captured by record web. How can I record it to download a pdf file.

Please look the screen shot of popup.

Browser Popup.PNG

https://www.katalon.com/resources-center/tutorials/handle-file-uploads/ simply seems outdated:
In section “Verify a Downloaded File” (because of which that page title ought to state more clearly that it doesn’t just deal with uploads, and the API would obviously deserve a WebUI.downloadFile counterpart as well, e.g. allowing to specify destination file path&name on repeated downloads)…

  • Firefox may indeed ignore “Do this automatically for files like this from now on”

  • The browser preferences to work around this should be entered not directly under
    Project Settings > Execution > Default > Web UI > Firefox
    but rather in a firefox_profile of Dictionary type on its sub-form Dictionary Property Builder

  • As of Katalon 5.3.1 at least, the drop-down offers no Integer type anymore (now Number, hence of value 2.0) and the proper parameter browser.helperApps.neverAsk.saveToDisk e.g. for a workbook is application/vnd-ms-excel of String type, per mimeTypes.rdf (reference to which under the user-specific Mozilla/Firefox/Profiles directory should be made) - not fully visible either in the current https://d1h3p5fzmizjvp.cloudfront.net/wp-content/uploads/2017/12/08113053/Verify-a-Downloaded-File.png

  • To check whether the above parameters are properly passed when Run:
    Log Viewer > Open browser driver > Starting Firefox > User set Firefox profile preference

Katalon_Firefox_suppress_Save_dialog.png

1 Like

BTW as commented in the code at the above site, there’s room for improvement in the current approach:

driver.findElement(By.linkText(‘smilechart.xls’)).click()

‘Wait for Some time so that file gets downloaded and Stored in user defined path’

WebUI.delay(10)

‘Verifying the file is download in the User defined Path’

Assert.assertTrue(isFileDownloaded(downloadPath, ‘smilechart.xls’), ‘Failed to download Expected document’)

I.e. several issues:

  1. The name of the destination file is hardcoded twice, but (while the first occurrence stays the same) browser or OS might rename it (causing the assertion to look at the oldest copy only) e.g. by appending “(1)” etc. on repeat(s).
  2. A timeout is to determine that an action has failed,
    never to assume (as above) that it must have completed.

There really should be a way to assign a file name to save to, and determine/wait for when the browser has indeed completed the download (i.e. until top-left corner icon in Firefox or suppressed Save as…/progress bar pop-ups would return/stop moving).

Hi Dime,

Actually I have created automated testing by click on download button to download file (.pdf, .xlsx, etc.) but every download in Firefox browser, it showed the pop up dialog to confirm.

So, how to access this pop up or let it download automatically without asking in Firefox browser?

Please help…

Firefox popup prompt bug.jpg

Hi Dime/there,

Using Katalon, am trying to download a file on click of a link in an Application.

i.e. On click of a Link the download should begin without asking an
option whether to save the file or opent with Firefox Browser.

I am Using

**_browser.helperApps.neverAsk.saveToDisk String_** **_application/pdf_**

Actual Result:

When I set above code through Project Settings–>Execution–>Default–>WebUI–> Firefox the file is not getting saved automatically,
rather it is asking for an option to save or open. Am Using a Data
driven Approach where I am getting the elements from an PDF File.

Can Anyone please help me out?

Arun K Dey said:

Hi Dime/there,

Using Katalon, am trying to download a file on click of a link in an Application.

i.e. On click of a Link the download should begin without asking an
option whether to save the file or opent with Firefox Browser.

I am Using

**_browser.helperApps.neverAsk.saveToDisk String_** **_application/pdf_**

Actual Result:

When I set above code through Project Settings–>Execution–>Default–>WebUI–> Firefox the file is not getting saved automatically,
rather it is asking for an option to save or open. Am Using a Data
driven Approach where I am getting the elements from an PDF File.

Can Anyone please help me out?

I never got it to work with auto save parameters that you enterd in PROJECT SETTINGS.
Instead i used java ROBOT class to simulate mouse and keyboard interaction.

When you look at your popup, when it is opend, if you pres ARROW DOWN on keyboard it will select SAVE FILE. After that if you pres ENTER it will open windows explorer save window.
If you watch closely you can see that file name is colored in BLUE, and that means you can start typing and you can give it any name you want. After you finished typing you can pres ENTER and it will save the file. In the file name you can type C:\MyFileName and it will save it in C:\ directory
which means you can give any path you want and store your file there.

And you can use robot class like this:

import java.awt.Robot as Robot

import java.awt.event.KeyEvent as KeyEvent

Robot rb = new Robot()

rb.keyPress(KeyEvent.VK_ENTER)

WebUI.delay(1)

rb.keyRelease(KeyEvent.VK_ENTER)

WebUI.delay(2)

1 Like

crokatalontest said:

Arun K Dey said:

Hi Dime/there,

Using Katalon, am trying to download a file on click of a link in an Application.

i.e. On click of a Link the download should begin without asking an
option whether to save the file or opent with Firefox Browser.

I am Using

**_browser.helperApps.neverAsk.saveToDisk String_** **_application/pdf_**

Actual Result:

When I set above code through Project Settings–>Execution–>Default–>WebUI–> Firefox the file is not getting saved automatically,
rather it is asking for an option to save or open. Am Using a Data
driven Approach where I am getting the elements from an PDF File.

Can Anyone please help me out?

I never got it to work with auto save parameters that you enterd in PROJECT SETTINGS.
Instead i used java ROBOT class to simulate mouse and keyboard interaction.

When you look at your popup, when it is opend, if you pres ARROW DOWN on keyboard it will select SAVE FILE. After that if you pres ENTER it will open windows explorer save window.
If you watch closely you can see that file name is colored in BLUE, and that means you can start typing and you can give it any name you want. After you finished typing you can pres ENTER and it will save the file. In the file name you can type C:\MyFileName and it will save it in C:\ directory
which means you can give any path you want and store your file there.

And you can use robot class like this:

import java.awt.Robot as Robot

import java.awt.event.KeyEvent as KeyEvent

Robot rb = new Robot()

rb.keyPress(KeyEvent.VK_ENTER)

WebUI.delay(1)

rb.keyRelease(KeyEvent.VK_ENTER)

WebUI.delay(2)

Thank you Crokatalontest…Now it’s working fine.

Arun K Dey said:

Hi Dime/there,

Using Katalon, am trying to download a file on click of a link in an Application.

i.e. On click of a Link the download should begin without asking an
option whether to save the file or opent with Firefox Browser.

I am Using

**_browser.helperApps.neverAsk.saveToDisk String_** **_application/pdf_**

When I set above code through Project Settings–>Execution–>Default–>WebUI–> Firefox the file is not getting saved automatically,
rather it is asking for an option to save or open.

3 more profile settings than this are needed, and in a particular structure, which aren’t visible so well from the screen shots available in the (partly outdated) documentation so far. Got it to work this way:

As I wrote on 2018-03-28 above though, by a few minor tweaks Katalon could vastly improve how to handle this in code.

Katalon Firefox Profile.png

2 Likes

Thank you Dime …

How we can achieve the same in Chrome???

I’m trying to download a CSV using FF58 using Katalon 5.5 but whatever prefs I set it still always shows the download dialog. FF still shows the dialog even though visiting about:config in FF shows the prefs being set. I can see the following being set:

browser.download.dir;C:\Downloads
browser.download.folderList;2
browser.download.manager.showWhenStarting;false
browser.helperApps.neverAsk.saveToDisk;text/csv

So it really looks like FF requires other preferences to be set?

OK I found the problem and added to the question on SO:

https://stackoverflow.com/questions/15954682/setting-selenium-to-use-custom-profile-but-it-keeps-opening-with-default

Preeti Diwakar said:

How we can achieve the same in Chrome???

In the updated version of Chrome, no browser popup will come. So, no need to write the above code in the case of chrome browser. Since, whenever you click on the download (pdf) button. It will be downloaded and saved automatically in the download folder section or your downloads location without any browser popup message.