self.driver = Chrome(CHROME_DRIVER) #初始化對象
self.driver.set_window_size(1280, 1024) #設置窗口大小
self.driver.execute_script(
'localStorage.setItem("pre_appadmin_login_2541044284@qq.com",JSON.stringify(%s))' % self.local_storage)#設置localStorage本地緩存
self.driver.get_screenshot_as_file(os.path.join(BASE_DIR, 'yanzheng.png'))#獲取當前窗口截屏並保存在程序文件根目錄
image_position = self.driver.find_element_by_id('imgcaptcha')#獲取驗證碼圖片元素
left = image_position.location['x']#獲取驗證最左邊位置
top = image_position.location['y']#獲取驗證碼上邊位置
right = left + image_position.size['width']#獲取驗證碼右邊位置
bottom = top + image_position.size['height']#獲取驗證碼下邊位置
open_img = Image.open('yanzheng.png')#打開屏幕截圖
open_img = open_img.crop((left, top, right, bottom))#使用獲取到的位置剪切圖片
open_img.show()#顯示圖片
output = input('輸入驗證碼結果:\n')