First, preface
When you use Python+webdriver for Web automation, you cannot handle the upload of a local file through Webdriver. This is a need for third-party tools to resolve this issue. The following describes how this tool (AutoIt) is used.
Second, the use of AutoIt
2.1, AutoIt download and installation
: Https://www.autoitscript.com/site
After downloading, directly click the exe file to install, here I will not be a chicken.
2.2, the use of AutoIt
After installation, in the computer All programs will be with the AutoIt V3 folder, open, there will be AutoIt Window Info (x64), Compile script to the. exe (x64), SciTE Script Editor three launcher program (Win7 , Win10 Click Start-All Programs, win8 to go to the program one by one search it), if not, you re-install it.
2.2.1, AutoIt Window Info (x64)
Click Automatic this program
This tool is used to get some information about the upload window by dragging the Finder tool directly onto the control you want to capture.
Get text box information
Get Open Button Information
2.2.2, SciTE Script Editor
Open the tool, enter the control information obtained above, save to UPFILE.AU3;
; Controlfocus ("title", "Text", ControlID) Edit1=edit instance 1
Controlfocus ("File Upload", "", "Edit1")
; Wait ten seconds for the Upload window to appear
Winwait ("[CLASS: #32770]", "", 10)
; Set the File name Thext on the Edit field
Controlsettext ("File Upload", "" "," Edit1 "," E:\Python\20170109 (pyton+selenium) \test.png ")
Sleep (2000)
; Click on the Open button
Controlclick ("File Upload", "", "Button1");
2.2.3, Compile Script to. exe (x64)
Use this tool to turn the above upfile.au3 into an executable EXE file
At this point, you have taken care of the local upload problem, and then only need to call this EXE executable in the script to
The Python script invocation example is as follows:
Os.system ("E:\Python\upfile.exe")
Python uses Webdriver to process uploading files (using AutoIt)