Download files using desired capabilities from Firefox and chrome NOT WORKING in 7.0.5 version

156 views
Skip to first unread message

Rishu Agra

unread,
Jul 20, 2020, 7:25:38 AM7/20/20
to Selenium Users
Hi Everyone:

There is one button which contains the pdf file. When i am clicking on it, it is not downloading in Downloads folder rather it is opening in new window. I tried with both Firefox browser and chrome options also.Nothing is working. What i have seen at the run the time when the browser is getting opened from Katalon studio the settings of chrome or firfox for PDF Documents change to open in new window rather than downloading. I have used the below code but it is not WORKING:
For Firefox i set the capabilities in Settings of katalon studio below is the screenshot:
as it is pdf file i used application/Pdf: 




For chrome i am using settings:

folder = new File(UUID.randomUUID().toString())

folder.mkdir()

ChromeOptions options = new ChromeOptions()

HashMap<String, Object> chromePrefs = new HashMap<String, Object>()

//chromePrefs.put("plugins.plugins_disabled", "Chrome PDF Viewer");
chromePrefs.put('profile.default_content_settings.popups', 0)

chromePrefs.put("safebrowsing.enabled",true)

chromePrefs.put('download.default_directory', getAbsoluteFile)

options.setExperimentalOption('prefs', chromePrefs)

options.addArguments('---download')

DesiredCapabilities cap = DesiredCapabilities.chrome()

//options.merge(cap);
cap.setCapability(ChromeOptions.CAPABILITY, options)

//cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability('download.prompt_for_download', 'false')

cap.setCapability('directory_upgrade', 'true')

WebDriver driver = new ChromeDriver(cap)

driver = DriverFactory.getWebDriver()

previewbtn = driver.findElement(By.xpath('//input[@value="Preview"]'))

previewbtn.click()

WebUI.delay(20)


This  previewbtn contains a pdf. 

I have also seen the video which you have posted on youtube.I applied the same code it is not working...I am able to generate UUID in project directory but the pdf is not getting downloaded.

Nothing is working. Please help me. 





Reply all
Reply to author
Forward
0 new messages