我想要比较2张图片。但是我收到了以下错误。
fp.seek(0)
AttributeError: 'WebElement' object has no attribute 'seek'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "D:\......\test_ImagePreview.py", line
107, in test_PlaylistExport
imCompare2 = Image.open(driver.find_element_by_xpath("xhtml:html/xhtml:body/xhtml:img"))
File "C:\Python34\lib\site-packages\PIL\Image.py", line 2254, in open
fp = io.BytesIO(fp.read())
AttributeError: 'WebElement' object has no attribute 'read'
第一张图片存储在我的电脑中,第二张图片来自网页。
我正在使用的脚本:
imCompare1 = Image_Path
imCompare2 = Image.open(driver.find_element_by_xpath("xhtml:html/xhtml:body/xhtml:img"))
Comparediff = ImageChops.difference(imCompare1, imCompare2).getbbox()
print (Comparediff)
来自DOM的:< xhtml:img src =“https://XXX.XX.XXX.XXX/Path1/Path2/Files.aspx?method=getPreview&fileid=5959&session=hddkdcgywtdw025u4ikiljk0”alt =“ttps://XXX.XX.XXX .XXX / Path1 / Path2 / Files.aspx?method = getPreview& fileid = 5959& session = hddkdcgywtdw025u4ikiljk0 />
有人能告诉我,我做错了什么吗?正如它在Xhtml中。我如何比较网页上的图片?
答案 0 :(得分:0)
最后,我可以通过下面的代码将图像下载到我的系统来完成此操作。
img_url = "https://www.google.co.in/images/branding/googlelogo/2x/googlelogo_color_272x92dp.png"
fileN = open('Imgfile.png','wb')
fileN .write(urllib.request.urlopen(img_url).read())
fileN .close()
然后比较两个存储的图像