[英]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. 在我的代码中,在通过element.submit()
提交表单之前和之后,我保存了屏幕截图。 I also have logging surrounding the call to webdriver.save_screenshot()
. 我还记录了对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. 我看到的是, 有时保存屏幕截图会阻止该过程,直到我杀死chromedriver
和/或Chrome
进程。
This screenshot locking up Chrome happens on both Mac OS X and Ubuntu 16.04 Server (AWS EC2). 锁定Chrome的此屏幕截图同时在Mac OS X和Ubuntu 16.04 Server(AWS EC2)上发生。 I have only been able to get this to repro on headless Chrome on the Mac. 我只能在Mac上的无头 Chrome上进行复制。
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. 我现在的猜测是,它与element.submit()
因为除了调用之后(立即),我还没有看到这种情况发生。
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: 这不是一个理想的解决方案,但是为了避免无限期地阻塞,我使用了Python的threading
模块来截取如下截图:
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. 如果发生异常,则我退出或终止浏览器进程,这也会导致线程死亡。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.