webdriver保存验证码截图

时间:2022-07-31 23:16:14

element = wait.until ( EC.visibility_of_element_located((By.CSS_SELECTOR,'.quc-main .quc-field-captcha img')))  #等待验证码加载完毕

browser.save_screenshot('screenshot.png')

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('screenshot.png')
im = im.crop((left,top,right,bottom))
im.save('screenshot.png')