思路: 
1、首先截图整个页面
2、定位截图的对应元素
3、获取该元素的坐标及大小
4、从大图截取小图


代码:

# coding:utf-8
from selenium import webdriver
from PIL import Image
driver = webdriver.Chrome()
driver.get('http://www.baidu.com/')

driver.save_screenshot('button.png')
element = driver.find_element_by_id("su")
print(element.location) # 打印元素坐标
print(element.size) # 打印元素大小

left = element.location['x']
top = element.location['y']
right = element.location['x'] + element.size['width']
bottom = element.location['y'] + element.size['height']

im = Image.open('button.png')
im = im.crop((left, top, right, bottom))
im.save('button.png')

相关文章:

  • 2021-09-25
  • 2022-01-12
  • 2021-12-23
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2022-01-10
  • 2021-12-06
猜你喜欢
  • 2021-11-08
  • 2023-03-09
  • 2021-12-29
  • 2021-10-11
  • 2021-05-16
  • 2022-12-23
相关资源
相似解决方案