Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98376

Fail to download file with opened new tab in headless mode on Linux

$
0
0

As this answer by myself: How to download files headless in Selenium (Java) when download happens in new tab?

If download button trigger download action in opened new tab, I will switch to new tab and send command(as below code) to download file.

def enable_download_in_headless_chrome(self, driver, download_path):
    driver.command_executor._commands["send_command"] = ("POST", '/session/$sessionId/chromium/send_command')
    params = {
        'cmd': 'Page.setDownloadBehavior',
        'params': {'behavior': 'allow', 'downloadPath': download_path}
    }

    driver.execute("send_command", params)

I found that the above method failed on linux occasionally.

When driver got the error, it would be crashed for a long time. (I detect the situation from my error handling with retry.)

Error message:

Message: timeout
(Session info: headless chrome=77.0.3865.120)

And I have looked at solution with the issue discussion but no one can solve it: https://bugs.chromium.org/p/chromium/issues/detail?id=696481

I guess the root cause is that I send enable download command before the new tab in ready state?

Please help me to find the solution. Thanks.


Viewing all articles
Browse latest Browse all 98376

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>