whatismyname123
whatismyname123

Reputation: 159

Selenide can't download PDF

I had some trouble using Selenide's download function. This is my flow:

  1. click on button
  2. button opens new tab which shows pdf file and url is: blob:https://hostname.apps.something.else/9365b3ab-f0ad-45e9-85d2-db7e2fb5fd2e

So basically the new tab is opened in Chrome PDF Viewer. I tried to click on the hidden download button in the new tab but no luck. My thinking got me to the idea of when I click that button, this new tab shouldn't open, the download should start. That would mean settings some Configuration preferences like I did below:

Configuration.browserCapabilities = new DesiredCapabilities();
Configuration.browserSize = "1920x1080";
Configuration.fileDownload = FileDownloadMode.FOLDER;
Configuration.downloadsFolder = "./src/pdfs";
Configuration.proxyHost = "30.40.34.82";
Configuration.proxyPort = 8080;
Configuration.proxyEnabled = true;
Configuration.fileDownload = FileDownloadMode.PROXY;
Configuration.browserCapabilities.setCapability("plugins.always_open_pdf_externally", true);
Configuration.browserCapabilities.setCapability("download.prompt_for_download", false);
Configuration.browserCapabilities.setCapability("pdfjs.disabled", true);

The problem is that, this still opens new tab, and I get no such element found

File file = applicationList.printButton.download(30000);

Upvotes: 0

Views: 1655

Answers (2)

Andrei Solntsev
Andrei Solntsev

Reputation: 510

Why do you first set Configuration.fileDownload to FOLDER and then to PROXY? No need to set it twice.

I think you cannot download the file via PROXY because links of type blob: don't fetch file content from the server.

I think you can just remove all these lines:

Configuration.proxyHost = "30.40.34.82";
Configuration.proxyPort = 8080;
Configuration.proxyEnabled = true;
Configuration.fileDownload = FileDownloadMode.PROXY;
Configuration.browserCapabilities.setCapability("plugins.always_open_pdf_externally", true);
Configuration.browserCapabilities.setCapability("download.prompt_for_download", false);
Configuration.browserCapabilities.setCapability("pdfjs.disabled", true);

Selenide method FOLDER should download the file without all these tricky settings.

Upvotes: 1

John Doe
John Doe

Reputation: 1

Try it

System.setProperty("chromeoptions.prefs", "plugins.always_open_pdf_externally=true")

Upvotes: 0

Related Questions