0

This link is a PDF file that opens in Chrome PDF file. Can I somehow save this PDF file from this page? I run chrome with such settings

driver.SetPreference "download.default_directory", "c:\chr"
driver.SetPreference "download.directory_upgrade", True
driver.SetPreference "download.prompt_for_download", False

but when you press CONTROL + S, the save as window still appears. May be i can download PDF directly from Chrome?

UPDATE CODE:

This works fine:

Public Sub browser_open()


Set driver = New ChromeDriver

driver.SetPreference "download.prompt_for_download", False
driver.AddArgument "--kiosk-printing"

driver.Start "chrome"
driver.get "https://data2.manualslib.com/pdf3/53/5221/522008-haier/washing_machine.pdf?b76112ef24159605ca8df71689bce0a7"

driver.SendKeys keys.ArrowDown
driver.SendKeys keys.ArrowDown, keys.ArrowLeft

But if i want to press "CONTROL + S":

driver.SendKeys keys.Control, "s"

nothing happens.

giovanii111
  • 47
  • 1
  • 8
  • 1
    It is a website url rather than a direct download link. If you intend to download via pressing download in chrome it is in shadow-root and will need API interfaces. See an example here: https://stackoverflow.com/a/52906215/6241235 – QHarr Jun 29 '20 at 23:23
  • Thanks for your answer. I try to work with your example, but ```.SendKeys keys.Control, "s"``` is not work for me on this PDF page [link](https://data2.manualslib.com/pdf3/53/5221/522008-haier/washing_machine.pdf?b76112ef24159605ca8df71689bce0a7), after ```.SendKeys keys.Control, "s"``` Save as dialog is not open – giovanii111 Jun 29 '20 at 23:44
  • 1
    Have you got the right window handle? – QHarr Jun 30 '20 at 04:34
  • I have only one Chrome window. I'm updated my code. Where is my error? – giovanii111 Jun 30 '20 at 05:37
  • 1
    I meant using the solution in the link I sent. You can't interact with the print pdf via shadow-root without API call – QHarr Jun 30 '20 at 07:55
  • But ```driver.SendKeys keys.Control, "s" ``` it should work without resorting to the API? – giovanii111 Jun 30 '20 at 12:05

1 Answers1

1

I apologize for my English, I use Google Translate.

This command runs a script that creates a link element to save the page as a pdf file, and then simulates clicking on the link.

driver.ExecuteScript "var a = document.createElement('a'); a.href = '" & driver.url & "'; a.download = 'My file.pdf'; document.body.appendChild(a); a.click();"

Below is the full code:

Public Sub browser_open()

Set driver = New ChromeDriver

driver.SetPreference "download.prompt_for_download", False
driver.AddArgument "--kiosk-printing"

driver.Start "chrome"
driver.Get "https://data2.manualslib.com/pdf3/53/5221/522008-haier/washing_machine.pdf?b76112ef24159605ca8df71689bce0a7"
driver.ExecuteScript "var a = document.createElement('a'); a.href = '" & driver.url & "'; a.download = 'My file.pdf'; document.body.appendChild(a); a.click();"

Note! It may take a few seconds for the download to begin.

Note! To download multiple files you need to confirm this in the popup window, I do not know how to do this programmatically.