简体   繁体   English

为什么保存截图有时会在Selenium +无头Chrome + Python 2.7中被无限期阻止?

[英]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 XUbuntu 16.04 Server(AW​​S 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.

相关问题 如何使用带有 Selenium 的 Headless Google Chrome 保存手机屏幕截图 - How to save mobile screenshot using Headless Google Chrome with Selenium 阻止在 Selenium 无头 Chrome [python] 上下载图像 - Block the download of images on Selenium headless Chrome [python] 使用python硒和Firefox或Chrome浏览器获取整个页面的截图 - Taking screenshot of whole page with python selenium and Firefox or Chrome headless Chrome / Firefox在新标签页中打开PDF,并且不会以无头模式保存它(Selenium + Python) - Chrome/Firefox opens PDF in new tab and does not save it in headless mode (Selenium+Python) 为什么使用 Chromium 的 python selenium 中的 headless 不起作用? - Why does headless in python selenium with Chromium not work? Chrome + selenium + python 适用于有头 chrome,不适用于无头运行 - Chrome + selenium + python works for headed chrome, does not work for headless run 为什么 Selenium 在 Chrome headless 模式下没有点击想要的按钮? - Why does Selenium not click the desired button in Chrome headless mode? AttributeError: 'NoneType' 对象在通过 Python 使用 Selenium 使用无头 Chrome 截取屏幕截图时没有属性 'encode' 错误 - AttributeError: 'NoneType' object has no attribute 'encode' error while taking screenshot with headless Chrome using Selenium through Python python selenium chrome headless中的文件下载路径设置不适用 - The file download path setting in python selenium chrome headless does not apply Python-Selenium:Chrome 无头设置不适用于“WebDriverWait” - Python-Selenium: Chrome headless setting does not work with "WebDriverWait"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM