4

I'm using Playwright to upload a file and download the result. When the inputfiles are large, and it takes a long time to process I get a timeout from playwright; it takes to long for the button "Download" to appear.

    raise exception
playwright._impl._api_types.TimeoutError: Timeout 30000.0ms exceeded while waiting for event "download"
=========================== logs ===========================
waiting for event "download"
============================================================

How can I let playwright wait longer on that specific event?

with page.expect_download() as download_info:
    page.locator("text=Download").click()
    #todo: wait longer?
download = download_info.value
# expect(page).to_have_url("http://localhost:8080/swagger/#/NER/post_ner")
path = download.path()
suggested_filename = file_out
download.save_as(suggested_filename)
hardkoded
  • 18,915
  • 3
  • 52
  • 64
Tralala
  • 233
  • 2
  • 10

3 Answers3

5

If you know that the click will take a while, you can set a timeout:

page.locator("text=Download").click(timeout=60000)
hardkoded
  • 18,915
  • 3
  • 52
  • 64
  • 2
    Adding on, remember that the timeout is in ms. – Charchit Agarwal Jul 06 '22 at 16:55
  • 1
    I tried this: age.locator("text=Download").click(timeout=120000), but it's ignored. I get the same error message: playwright._impl._api_types.TimeoutError: Timeout 30000.0ms exceeded while waiting for event "download" This worked: page.set_default_timeout(timeout=120000) – Tralala Jul 07 '22 at 04:04
0

You can also set the timeout to 0 if your not concerned with it taking too long. Though this can lead to it potentially taking hours...or never end if it gets stuck loading. A timeout of some value other than 0 is probably best practice.

page.locator("text=Download").click(timeout=0)

pynoob
  • 11
  • 2
0

Not sure if this will help, but I have used the code below successfully many times:

with page.expect_download(timeout=0) as download_info:

Setting timeout=0 causes it to wait for as long as it takes to download.

Adrian
  • 491
  • 4
  • 5