Asked 7 years, 8 months ago. Active 7 months ago. Viewed 45k times. My code looks like this: Thread. How can I make the webdriver to wait until a download complete — qaepk. This is stepping beyond the capabilities of WebDriver, once a download starts, it is no longer a browser operation, hence WebDriver cannot control it as such. Check out this blog post which is very informative when it comes to this very topic.
Add a comment. Active Oldest Votes. This is excellent for when it applies. I deal with plenty of sites that don't use something as simple as putting the file in href , but if they do, this is great. This is not wrong, I also used this method before. And to make this work with authentication, u can get the cookies from selenium's driver and append to the http request. But, Its a pain when the download link is generated by js. And also you cant test if clicking the download button actually downloads the file.
I switched back to the normal thing, click the button and do the file. And for selenium in a hub-node architecture, I use ssh to ls or dir the file for existence. First of all, thank you very much for this solution. It makes things a lot easier and cleaner to manage. I have a doubt about the stream keyword argument though. Can you please elaborate on what the purpose of that argument is? So, first you need this: import com. Function import java. Now here,you can continue your flow of execution after download completes.
Still make sure you dont initiate your download using selenium, instead extract the link using selenium and use requests module to download. Download using requests module. As answered before, there is no native way to check if download is finished. So here is a helper function that does the job for Firefox and Chrome. One trick is to clear the temp download folder before start a new download.
Also, use native pathlib for cross-platform usage. This works if you are trying to check if a set of files more than one have finished downloading. With Chrome, files which have not finished downloading have the extension. If you set your download directory properly, then you can wait until the file that you want no longer has this extension. In principle, this is not much different to waiting for file to exist as suggested by alecxe - but at least you can monitor progress in this way.
So redirect the function that starts the download. After that rename it. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. Ask Question. Asked 5 years, 11 months ago. Active 2 months ago. Viewed 66k times. Add a comment. Sign up or log in Sign up using Google. Sign up using Facebook.
Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Who owns this outage? Building intelligent escalation chains for modern SRE.
Podcast Who is building clouds for the independent developer? Featured on Meta. Now live: A fully responsive profile. Is there a way in selenium to wait-for-download or equivalent? I could throw in a Thread. I had the same problem. I invented something to solve the problem.
A tempt file is created by Python with '. So, if still we have the temp, python can wait for 10 second and check again if the file is downloaded or not yet. Neither problemc an be directly solved by Selenium yet - 2. But they can also be solved by simply sending an automated keypress at the OS level that simulates the enter key works for Firefox, a little harder on some versions of Chrome and Safari.
If you're using Java, you can use Robot to do that. Other languages have similar toolkits to do such a thing. The second issue is probably best solved with some sort of proxy solution.
For example, if your browser was configured to go through a proxy and that proxy had an API, you could query the proxy with that API to ask when network activity had ended. This is Chrome-testing-only solution for controlling the downloads with javascript.. This suites you if you just need to test some info note eg. Naturally you need to control step 1. This falls under the "things that can't be automated" category. Selenium is built with JavaScipt and due to JavaScript sandbox restrictions it can't access downloads.
0コメント