想截取一下验证码的图片,但是截图后和验证码的位置不对应,不知道是不是写法有问题,还是有其余的因素在影响,selenium 用的 Chrome 浏览器 附上操作代码 browser.save_screenshot('bdbutton.png') element = browser.find_element_by_xpath('//*[@id="login-yzm_img"]') # 找到验证码图片 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('bdbutton.png') im = im.crop((left, top, right, bottom)) im.show() im.save('bdbutton.png')
