python packing tool pyinstaller instructions

2022-12-31   ES  

Purpose: When the program runs errors, you can know how to know more intuitively through the screenshot file

body is wrong, and the screenshot of the window refers to saving errors to the specified location.
Loading method: Driver.get_screnshot_as_file (FILENAME)

The file name of the
screenshot must end with PNG
FILENAME’s file directory must be created manually


# # #
import time
from selenium import webdriver
from import  By

# Website instantiation
driver = webdriver.Chrome()
driver.get("Website Path")

	# Input username
	# Input password

except Exception as e:
	raise e


2.1 What is the verification code?
Verification code refers to a randomly generated information (numbers, letters, Chinese characters, pictures, arithmetic questions), etc. In order to prevent malicious request behaviors and increase the security of the application. It is also necessary to register or log in during automation, so the verification code needs to be processed.
2.2 Verification Code processing method
1. Remove the verification code by the development operation and use it in the test environment
2. Set up a universal verification code by development operation, and generally only use in the test environment.
3. Verification code recognition technology is difficult to reach 100%due to the difficulty of technology. It is generally not recommended to use
4. Record Cookie: Skip the login operation by recording cookie.
2.3 Cookie Principle
Cookie is generated by the web server and saved on the user browser. It can include user -related information.
cookie data format: key value pair (dictionary in python)
COOKIE: The client request the server. If the server needs to record the user status, a Cookie data is issued to the client browser
Cookie: When the browser requested the website again, the browser submits the request data with the Cookie data to the server, and the server checks the cookie to identify the user status.
2.4 Selenium operation cookie
Driver.get_cookie (name) Get the cookie information referring to the name of the name returns a dictionary
Driver.get_cookies () Get all cookie information, and return a list
Driver.add_cookie (Dict_Cookie) to the browser -driven to add cookies, dict_cookie is a dictionary
Note: How to confirm which cookie is used to control the user’s permissions:
1. You can ask the development classmates
2. Comparison of cookies before and after login, can be used to control user permissions than before login.
3. Can not exit after logging in, and after exiting, it is equivalent to cookies.

  • Write a function that generates a mobile phone number through the Python code (it will generate more junk data)
  • Before registering, backup a database (only need to be done once), execute the registered use case, and then restore the database after each execution is performed (if the amount of database database is large, then the recovery time will be relatively long, the efficiency will be efficient, efficiency Compared)
  • Through the Python script directly to delete new users in the database (to be familiar with the database business at the bottom, you must know what the registered users are in the table)


import random
import time
from selenium import webdriver
from import By
# Define the function name of obtaining the mobile phone number
def get_mobile():
    mobiles = ['130', '131', '134', '135']  
    # Determine the format of the mobile phone number
    number = str(int(time.time()))[2:]  
    # The latter 8 digits of the mobile phone number through the timestamp (must not be repeated)
    mobile = random.choice(mobiles)+number  
    # The three digits of the handle number format are added with the latter 8 digits
    return mobile
driver = webdriver.Chrome()
driver.get("Website Path")


1. Install Autoit V3 tool. AutoIT V3 tool is used to view Windows window information and control information.
2. Install the Pyautoit module.

  • Press file
  • After entering the decompression directory in the Windows window, enter CMD in the address bar
  • Perform the following python Install

4 4:

import time
import autoit
from selenium import webdriver
from selenium.webdriver import ActionChains
from import By
driver = webdriver.Chrome()
# Click the camera button above Baidu
driver.find_element(By.CSS_SELECTOR, ".soutu_btn").click()
# Click to select file
ele = driver.find_element(By.CSS_SELECTOR, ".upload_pic")
# Define the mouse object
action = ActionChains(driver)
# Call the mouse event
# 5 5 Mouse event method
# For Windows operation
# Get the pop -up window by AutoIT
autoit.win_wait_active("Open", 3)  # 3 indicates time, second isunit# In the file select the address and file name of the file in the input box
autoit.control_send("Open", "Edit1",r"C:\Users\LiaoFei\Pictures\Saved Pictures\333.jpg")
# Click the opening button in the pop -up window
autoit.control_click("Open", "Button1")


Related Posts

[SHUI) Questions] 201808Dream

Note (5) Static library and dynamic library GDB debugger

B1040/A1093 -There are several PAT (timeout & test point 3, 4)

C ++ Different from the difference between Iterator and Constitrator and Const Iterator

python packing tool pyinstaller instructions

Random Posts

Spring Study Note and Use Spring Send Email

Judgment line segment intersection

plural java realizes LHW

Create Hibernate project in IDEA

Steam how to convert the district service (take PES2021 as an example)