I was trying to handle a browser dialog with Playwright for Python in Firefox (in this case, but I guess the browser does not matter), i.e. a dialog that was opened by Firefox to ask whether to open or save a file. The dialog pops up after I click a button. The link to the file is not exposed, so I cannot download it in another way.
I tried catching a dialog
event:
with page.expect_event("dialog") as page_info:
button = page.querySelector('button[id="download"]')
button.click()
which times out. I then thought I found the solution in this GitHub ticket. However, the following did not work either:
page.on("dialog", lambda dialog: dialog.accept())
page.click("button")
Do these kinds of dialog - in contrast to dialogs e.g. raised by JavaScript alert()
- not trigger a dialog
event? I think they may not, judging by the answers to this post: Is it possible to catch browser's File Open/Save dialog event using Javascript.
If so, how can I accept or dismiss such a dialog using python-playwright?
question from:
https://stackoverflow.com/questions/65875543/how-to-catch-browser-dialogs-e-g-download-or-open-with-playwright-for-pytho 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…