Selenium UI Automation codes: identifying input +

Ideas: Use UI + mode interface to find and retrieve the CAPTCHA verification code parameter input elements (with screenshots manner) (non-image verification code can not be achieved)

 

We visit Dangdang registration interface demo

1. Find the codes by selenium positioned and retained screenshot

1 introduction of selenium package, create web -driven, enter the login interface, execute correctly

2 Create a screenshot function : Find the verification code elements, cut the current picture

Positioning the captcha

Screenshot for verification picture

 

Get the code verification code using the upper left corner of image coordinates (x, y), acquired using the code verification picture length and width, obtaining horizontal and vertical coordinates of two corners (four sides x, y coordinates)

3 by four coordinate points of the two diagonals of the codes have been obtained in the theme codes (hereinafter interface to obtain a value)

Acquired screenshots

This part of the code to achieve

 

 

 

2.  New Get function codes, codes acquired by the interface method

1 This operation requires money, Reference Site: https://www.showapi.com/apiGateway/view?apiCode=184

2 Register Login and purchase packages (to spend money on the line, pay attention to consumption and the number of times of use) recommend buying the cheapest test, there is a need to say

3 Usage: According to the rules of the current code is 4 CHARACTERS letters, so we use only contain alphanumeric characters on the line

Check the type and length codes (codes current is four, and both the English alphabet)

Selecting a service type (thus identifying the content to be selected alphanumeric type)

4 then select the language to view the guidance process (FIG down on a roll)

Guidelines operation code appears after selecting the language, right click to download the SDK download (soft-develop-kit Software Development Kit)

Download a zip archive, unzip a py of the same name in different file format names

Into this document by reference and the working path, the method with reference to the code reference guide, and the need to download interface request requests library

Call up the file in the way we need three parameters ( url ; my_appid ; my_appsecret ) which interface address given above

 

 

 

my_appid and my_secret personal center after login - Get my application at my_secret need to enter a password

View appid

View password (you must first enter the password)

 

Other operation content -, and the content and length of the acquired identification document, the method used here only to show, there is described the use of the above parameters, requires individual configuration parameters, last call transmission request acquirer

Using the method described

Parameter Description

5 to complete the implementation of the code function codes

6 using the variable that receives the acquired verification code, locate the input box acquired codes

7 When everything is ready, click on the Run

 

 

 

 

 

 

 

Finally, attach all the code

from Selenium Import the webdriver
from the PIL Import Image
from ShowapiRequest Import ShowapiRequest


Driver = webdriver.Chrome ()
driver.get ( "https://login.dangdang.com/register.php?returnurl=http://book.dangdang.com/ ? _utm_brand_id = 11106 & _ddclickunion = 460-5-biaoti | ad_type = 0 | sys_id = 1 " )

DEF screen_shot ():
    driver.save_screenshot ( r" D: \ zhuce.png " ) # cut the figure below the current page left_angle = driver. find_element_by_id ( "imgVcode" ) .location # get codes left corner Print (left_angle) # View the captcha left corner coordinates left = left_angle [ "the X-"
    
    
    ] # Get codes images leftmost x coordinate Top left_angle = [ "y" ] # Get codes images uppermost y-coordinate Image driver.find_element_by_id = ( "imgVcode" ) # positioning of the entire image width = image .size [ "width" ] # acquired width of the image height = image.size [ "height" ] # acquired image height right + left width = # Get codes images rightmost x coordinate Down height = Top + # Get captcha lowermost y-coordinate Print (left, Top, right, Down) # print horizontal and vertical coordinates of the four corners openim = Image.open ( R & lt "D: \ zhuce.png" ) # open just under the cut the whole picture jietu = openim.crop ((left, Top, right, Down)) # screenshots (method Imagez in) by four coordinates obtained here are just two small brackets jietu.save (
    
    
    
    
    
    
    

    
    
    R & lt "D: \ xi.png" ) # codes taken and continues to save thumbnail DEF yanzhengma ():     YZ = ShowapiRequest ( "http://route.showapi.com/184-4" , "104 117" , " 6baff26b20aa48edb6584955c0e08559 " )     yz.addFilePara ( " Image " , r" D: \ xi.png " ) # small photo source code yz.addBodyPara ( " typeId " , " 24 " ) # this is a pure digital English, I type 24 you can yz.addBodyPara ( "convert_to_jpg" , "0" ) # photos do not do the type conversion yz.addBodyPara ( "needMorePrecise" , "1") # Precision conversion res = yz.post (). Json ( )




    
    
    
    # Fetch response json format convenient value D = RES [ "showapi_res_body" ] [ "the Result" ] # Get the value of the codes in the Result Print (D) # print return D # returns IF __name__ __ == "__main__" :     screen_shot ()     C = yanzhengma () # assigned for inputting driver.find_element_by_id ( "txt_vcode" ) .send_keys (C)
    
    
    




    

 

 

 

 

 

 

 

 

 

Add that this package has the number and time constraints, want to know the usage can log in and view instant case

Guess you like

Origin www.cnblogs.com/wangx123sec/p/11495103.html