我无法获取屏幕图像。上周使用Firefox和Gekodriver 21进行了工作,但是更新后的Firefox需要更新到Gekodriver 23。
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from PIL import Image
from io import BytesIO
driver = webdriver.Firefox()
driver.get("https://www.google.co.uk/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png")
img_save = "test.png"
logo = driver.find_element_by_tag_name('img').screenshot_as_png
im = Image.open(BytesIO(logo))
im.save(img_save)
driver.quit()
Anaconda控制台错误消息
(base) C:\Users\Peter\MyScripts>python test.py
Traceback (most recent call last):
File "test.py", line 24, in <module>
im = Image.open(BytesIO(logo)) # uses PIL library to open image in memory
File "C:\ProgramData\Anaconda3\lib\site-packages\PIL\Image.py", line 2585, in open
% (filename if filename else fp))
OSError: cannot identify image file <_io.BytesIO object at 0x000002062F5EC990>
和gekodriver日志
1540653963940 mozrunner::runner INFO Running command: "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\Peter\\AppData\\Local\\Temp\\rust_mozprofile.KQzrqiT4ZMKB"
1540653969785 Marionette INFO Listening on port 61551
1540653970013 Marionette WARN TLS certificate errors will be ignored for this session
[Parent 4492, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Parent 4492, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Parent 4492, Gecko_IOThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 2728, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
[Child 2728, Chrome_ChildThread] WARNING: pipe error: 109: file z:/build/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1540653976442 Marionette INFO Stopped listening on port 61551
###!!! [Child][RunMessage] Error: Channel closing: too late to send/recv, messages will be lost
[GPU 8960, Chrome_ChildThread] WARNING:
###!!! [Child][MessageChannel::SendAndWait] Error: Channel error: cannot send/recv