New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
page.on not working for download dialogs? #460
Comments
Check out https://playwright.dev/python/docs/downloads for docs on how to manage downloads. Dialog event is for alert, confirm, prompt and onbeforeunload. |
Thank you for your quick reply! Unfortunately, there doesn't seem to be a download event triggered either. I've added a full example that triggers the mentioned dialog for a pdf download:
PS: I am aware that I could just directly download the file in this example. However, in my actual case, it is a blob file which I cannot access directly. |
There are multiple issues here:
Here is an example that works for me:
from playwright.sync_api import sync_playwright
import os
with sync_playwright() as p:
b = p.firefox.launch(headless=False,downloads_path=os.getcwd())
p = b.new_page(accept_downloads=True)
p.goto('https://www.webfx.com/blog/images/assets/cdn.sixrevisions.com/0435-01_html5_download_attribute_demo/html5download-demo.html')
with p.expect_download() as download_info:
p.click('text=DOWNLOAD HTML DOCUMENT')
download = download_info.value
print(download.path()) Let me know if that does not help. |
@dgozman Thank you very much for your answer. And while your example works fine, unfortunately, I don't seem to be able to adapt it to my problem. The thing is that in my case the embedded pdf viewer does not open as a result on a click on a link ( Is that normal / expected behavior? As a human, I can click the download button in the embedded PDF viewer and save the file. Shouldn't playwright somehow enable me to do the same? The only workaround I came up with thus far is running in headful mode, clicking the button and then sending an Enter press. But that does not let me modify the filename, etc. |
Embedded PDF viewer is not a part of the web, it is a part of the browser, so we don't automate it. |
Ok, thank you for the clarification. I thought since the embedded PDF viewer is based on |
In some cases it can be helpful to avoid dialogs entirely. If you open Chrome in headless mode, you won't get dialogs.
|
I was trying to handle a browser dialog in (in this case) firefox, i.e. a dialog opened by firefox to ask whether to open or save a file. The dialog pops up after I click a button.
I thought I found the solution in #396. However, the following did not work:
Do these kinds of dialog not trigger a "dialog" event? How can I accept or dismiss such a dialog?
The text was updated successfully, but these errors were encountered: