Selemiun automated test login verification code processing

Source: Internet
Author: User
Tags xpath finder
Selemiun automated test login verification code processing1. Installation of software and plug-ins 1. Firefox browser version (55.0 (x64 ZH-CN ):
Https://www.cnblogs.com/sandysun/p/7838113.html
Plugin installation:
(1) firebug
(2) selenim ide
(3) XPath finder 2. Python and editor Installation
(1) Python 3.7.0
(Download Firefox driver geckodriver.exe 2.32 and save it in the python \ py3 installation path) pycharm 2018
(2) download selenium3.14.1 (file-setting-Project: code-projectinterpreder) 3. The installation path set by the following variables in the environment:
JDK
Python3
Firebox
Tesseract-OCR 4. Complete the above configuration to test the simple page. To enter a verification code, you need to download the following plug-ins:
(1). Tesseract-OCR (image recognition plug-in). Images cannot be recognized without this plug-in.
(2) download the pillow image package in pycharm. Ii. pycharm write the following code to run from selenium import WebDriver
Import time
Import pytesseract
From Pil Import image, imageenhance
Driver = WebDriver. Firefox ()
Driver. maximize_window ()
Driver. Get ("https://cas.gzccc.edu.cn/lyuapServer/login ")
Driver. save_screenshot ("D: // Python/picture/1.png ")
Verification = driver. find_element_by_xpath ("/html/body/Div [2]/Div [2]/Div/form/Div [3]/Div [3]/IMG ") user = driver. find_element_by_xpath ("// * [@ ID = \" USERNAME \ "]")
Passa = driver. find_element_by_xpath ("// * [@ ID = \" password \ "]")
Shuru = driver. find_element_by_xpath ("// * [@ ID = \" j_captcha_response \ "]")
Denglu = driver. find_element_by_xpath ("/html/body/Div [2]/Div [2]/Div/form/Div [4]/input [3]")
Location = verification. Location
Size = verification. Size
Ran = image. Open ("D: // Python/picture/1.png") # open an image
Box = (1023,410,111)
Ran. Crop (box). Save ("D: // Python/picture/2.png ")
#4. Obtain the verification code image and read the verification code
Imagecode = image. Open ("D: // Python/picture/2.png ")
# Imagecode. Load ()
Sharp_img = imageenhance. Contrast (imagecode). Enhance (2.0) # image enhancement, binarization
Sharp_img.save ("D: // Python/picture/3.png ")
Sharp_img.load () # contrast enhancement
Time. Sleep (2)
# Print (sharp_img)
Code = pytesseract. image_to_string (sharp_img). Strip () # recognize images
#5. After receiving the verification code, enter it for verification.
User. send_keys ("?? ")
Passa. send_keys ("?? ")
Shuru. send_keys (CODE)
Denglu. Click ()
Time. Sleep (3)
Driver. Quit ()

Selemiun automated test login verification code processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.