Reputation: 17521
I am using selenium to automate some downloading tasks, but some pages start the downloads automatically and I need to know the links of those downloads during or after the download and the link is not available in the page.
How can I get the URL of the files that started downloading automatically?
Upvotes: 2
Views: 2768
Reputation: 1
This is a solution I would suggest:
chrome://downloads
document.getElementsByTagName("downloads-manager")[0]
.shadowRoot.children["mainContainer"]
.getElementsByTagName("downloads-item")[0]
.shadowRoot.getElementById("content")
After having the item you can get the name of the downloaded file and the download link or access the file icon and the closing x For example, extending the command above by
.getElementById("file-link").text will give you the filename.
Upvotes: 0
Reputation: 2766
If you are using Chrome to run your selenium scripts you can just navigate to the chrome://downloads/ and get the latest download file's URL.
Or you can fire a Ctrl+J keyboard action to the browser using java robot classes and open the tab.
(Chrome downloads page is a html page and you can capture elements in it)
Upvotes: 2