简体   繁体   中英

Why does save screenshot sometimes block indefinitely in Selenium + headless Chrome + Python 2.7?

In my code, I save a screenshot prior to submitting a form via element.submit() and afterwards. I also have logging surrounding the call to webdriver.save_screenshot() . What I am seeing is that sometimes saving a screenshot blocks the process until I kill the chromedriver and/or Chrome processes.

This screenshot locking up Chrome happens on both Mac OS X and Ubuntu 16.04 Server (AWS EC2). I have only been able to get this to repro on headless Chrome on the Mac.

Any thoughts or suggestions on why this would occur? My guess at this point is that it has to do with element.submit() because I have yet to see this happen except (immediately) after that call.

This isn't an ideal solution but in order to keep from blocking indefinitely I've tapped into Python's threading module to take a screenshot like so:

import threading
t = threading.Thread(target=webdriver.get_screenshot_as_file, args=[fn])
t.start()
t.join(10)
assert not t.isAlive(), "Screenshot failed"

If an exception occurs then I quit or terminate the browser process which results in the thread dying off as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM