【发布时间】:2020-06-14 21:32:14
【问题描述】:
我正在尝试使用 screenshot_as_png 方法截屏特定的 web_element,但出现错误。当我在 Windows 10 上运行此程序时一切正常,但 它在我的 AWS EC2 Ubuntu 18.04 上失败
main.py
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--disable-notifications')
options.add_argument("headless")
options.add_argument("start-maximized")
options.add_argument("disable-infobars")
options.add_argument("--disable-extensions")
options.add_argument("--disable-gpu")
options.add_argument("--disable-dev-shm-usage")
options.add_argument("--no-sandbox")
chrome = webdriver.Chrome(options=options)
chrome.get('http://stackoverflow.com/')
element = chrome.find_element_by_css_selector('.-main.grid--cell')
element.screenshot() #Error!
chrome.quit()
错误如下:
selenium.common.exceptions.WebDriverException: Message: unknown command: session/5c9bda106805d0d80a3f5c7b63dbf410/element/0.35398631812343306-1/screenshot
我正在使用的设置:
(Session info: headless chrome=80.0.3987.87)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.15.0-1060-aws x86_64)
【问题讨论】:
-
如果可以,请尝试使用 Firefox。我在使用 Chrome 的 Mac 上遇到了同样的错误,但无论出于何种原因,Firefox 都能正常工作。
标签: python python-3.x selenium selenium-webdriver selenium-chromedriver