PyCharm+Python+Selenium automated testing dynamic verification code recognition

driver.find_element(by=By.ID,value='USERID').send_keys("admin")

driver.find_element(by=By.ID,value='PASSWORD_VIEW').send_keys("123456")

#ocr identification principle: first locate the verification code picture according to the class dl_yzm of the verification code, then save the screenshot of the verification code, then use ocr to identify, read out the verification code, and fill it into yzm_text

yzm=driver.find_element(By.ID,"yzm_text") #Verification code input box

yzmImage=driver.find_element(By.CLASS_NAME,"dl_yzm") #Verification code picture

yzmImage.screenshot("yzm.png") #Verification code screenshot, save as yzm.png

ocr=ddddocr.DdddOcr()

with open("yzm.png","rb") as fp:

image=fp.read()

catch=ocr.classification(image) #Verification code returned to catch

driver.find_element(By.ID,"yzm_text").send_keys(catch) #Fill the verification code recognized by ocr into yzm_text

driver.find_element(By.ID,"login-btn").click()

time.sleep(3000)

driver.close()

Guess you like

Origin blog.csdn.net/u012388338/article/details/129380764
Recommended