One, file upload operation
Win32gui. FindWindow (Ipclassname,ipwindowname)
From the top-level window, start looking for the matching Criteria window and return the handle to the window;
Ipclassname: Class name, can be seen in Spy + +;
Ipwindowname: Window name, name you can see on the title bar
Win32gui. FindWindowEx (Hwndparent=0,hwndchildafter=0,ipszclassname=none,ipszwindowname=none)
The search for the class name and form name matches the form, and returns a handle to the form, which returns 0 if it is not found;
hWndParent: If not, then the search handle is hwndparent window subform;
Hwndchildafter: If not 0, the sub-form is searched backwards from hwndchildafter in the order of Z-index;
Ipszclassname: Character type, is the window's class name, this can be found in Spy + +;
Ipszwindowname: Character type, is the window name, that is, the title bar can see the title
Win32gui. SendMessage (Hwnd,msg,wparam,iparam)
HWnd: integer type, the window handle of receiving the message;
MSG: int, the message to be sent, these messages are all predefined by Windows;
WParam: integer type, wParam parameter of message;
Iparam: integer type, iparam parameter of message;
such as: Baidu Network disk upload operation-click the Upload button pop-up file box
#文件上传操作--command line installation python-m pip install Pypiwin32, reboot after installation Pycharm
Import Win32gui
Import Win32con
Import Time
#一级顶层窗口
dialog = Win32gui. FindWindow ("#32770", "open")
#二级窗口
comboBoxEx32 = Win32gui. FindWindowEx (dialog,0, "ComboBoxEx32", None)
#三级窗口
ComboBox = Win32gui. FindWindowEx (comboboxex32,0, "ComboBox", None)
#四级窗口--File path input area
edit = Win32gui. FindWindowEx (combobox,0, "Edit", None)
#二级窗口--Open button
button = Win32gui. FindWindowEx (dialog,0, "button", None)
#1, input file path
filepath = "E:\\chromedriver.exe"
Win32gui. SendMessage (Edit,win32con. Wm_settext,none,filepath)
Time.sleep (5)
#2, click the Open button
Win32gui. SendMessage (Dialog,win32con. Wm_command,1,button)
Python-selenium--File upload operation