老师 不知道这个错是什么原因造成的,图片识别的代码可以运行,但按照4-11章节来运行,就会报错
-------------------------------------------------------- from page.register_page import Register_Page from util.get_code import GetCode class Register_Handle(object): def __init__(self,driver): self.driver = driver self.register_p = Register_Page(self.driver) def send_user_mail(self,email): self.register_p.get_email_element().send_keys(email) def send_user_name(self,name): self.register_p.get_username_element().send_keys(name) def send_user_password(self,password): self.register_p.get_password_element().send_keys(password) def send_user_code(self,filename): get_code_text = GetCode(self.driver) code = get_code_text.code_photo(filename) self.register_p.get_code_element().send_keys(code) def get_user_text(self,info,user_info): try: if info == 'user_email_error': text = self.register_p.get_email_error_element().text elif info == 'user_name_error': text = self.register_p.get_name_error_element().text elif info == 'user_password_error': text = self.register_p.get_password_error_element().text else: text = self.register_p.get_code_error_elemenet().text except: text = None return text def click_register_button(self): self.register_p.get_butten_element().click() def get_register_text(self): return self.register_p.get_butten_element().text ------------------------------------------------------ from handle.register_handle import Register_Handle class Register_business(object): def __init__(self,driver): self.register_h = Register_Handle(driver) def user_base(self,email,name,password,filename): self.register_h.send_user_mail(email) self.register_h.send_user_name(name) self.register_h.send_user_password(password) self.register_h.send_user_code(filename) self.register_h.click_register_button() def register_succes(self): if self.register_h.get_register_text() == None: return True else: return False def login_email_error(self,email,name,password,filename): self.user_base(email,name,password,filename) if self.register_h.get_user_text('email_error',"请输入有效的电子邮件地址") == None: return True else: return False def login_username_error(self,email,name,password,filename): self.user_base(email,name,password,filename) if self.register_h.get_user_text('user_name_error',"字符长度必须大于等于4,一个中文字算2个字符") == None: return True else: return False def login_password_error(self,email,name,password,filename): self.user_base(email,name,password,filename) if self.register_h.get_user_text('user_password_error',"最少需要输入5个字符") == None: return True else: return False def login_code_error(self,email,name,password,filename): self.user_base(email,name,password,filename) if self.register_h.get_user_text('code_error',"验证码错误") == None: return True else: return False ----------------------------------------------------- from PIL import Image from ShowapiRequest import ShowapiRequest import time class GetCode: def __init__(self,driver): self.driver = driver def code_photo(self,filename): self.driver.save_screenshot(filename) element_code = self.driver.find_element_by_id("getcode_num") left = element_code.location['x'] top = element_code.location['y'] right = element_code.size['width'] + left height = element_code.size['height'] + top im = Image.open(filename) new_image = im.crop((left, top, right, height)) new_image.save(filename) time.sleep(2) def code_infor(self,filename): self.code_photo(filename) r = ShowapiRequest("http://route.showapi.com/184-4", "73290", "90d9d5556af84a7b8d2fe02047b92c7c") r.addBodyPara("typeId", "35") r.addBodyPara("convert_to_jpg", "0") r.addFilePara("image", filename) res = r.post() print(res.text) text = res.json()['showapi_res_body']['Result'] return text