AutoIt is currently the V3 version, a free software that uses a similar basic scripting language designed to
WindowsGUI (graphical user interface) for automated operation. It uses analog keyboard keys, mouse
MovingAnd a combination of Windows/controls for automating tasks. Download AutoIt from the website and install it, the installation is complete in the menu, you will see the directory in Figure 4.13: Figure 4.13 AutoIt Menu AutoIt Windows info is used to help us identify Windows control information. Compile Script To.exe is used to generate AutoIt exe execution files. Run script is used to execute the AutoIt script. The SciTE script Editor is used to write AutoIt scripts.
Save the above HTML code as a uplad.html file, open through the browser, the effect is as follows: The following to operate upload.html upload pop-up window as an example to explain the autoit implementation of the upload process. 1, first open the AutoIt Windows Info tool, mouse click on Finder tools, the mouse will become a small fan-shaped icon, hold down the left mouse button to drag the control to be recognized. Figure 4.14 autoit Windows Info recognizes the "File name" input box control diagram 4.15 autoit Windows info recognizes the "open" button control 4.14, 4.15, obtained by AutoIt windows info The following information. The title of the window is "Select Files to load" and the heading is "#32770". The file name input box has the class "Edit" and instance "1", so Classnamenn is "Edit1". The Open button's class is "button" and instance is "1", so Classnamenn is "Button1". 2. Open the SciTE Script Editor and write scripts according to the control information that AutoIt Windows Info recognizes. Controlfocus ("title", "Text", ControlID) Edit1=edit instance 1 controlfocus ("Select File to Load", "", "Edit1"); Wait ten seconds for the Upload window to appear winwait ("[CLASS: #32770]", "", 10); Set the file name text on the Edit field controlsettext ("Select File to Load", "", "Edit1", "D:\\upload_file.txt") Sleep (2000); Click on the Open button Controlclick ("Select File to Load", "", "Button1"); The Controlfocus () method is used to identify window windows. Winwait () Sets 10 seconds to wait for the display of the window, similar in usage to the implicitly_wait () provided by Webdriver. Controlsettext () is used to enter the path to the local file in the file name input box. The sleep () method here is the same as the sleep () method provided by the time module in Python, but it is in milliseconds and Sleep (2000) represents a fixed sleep of 2000 milliseconds. Controlclick () is used to click the "Open" button in the Upload window. AutoIt's script has been written, and you can run a script from the menu bar "Tools" and "Go" (or press keyboard F5)! Note the Upload window is currently open at run time.
3, the script runs normally, save it as UPFILE.AU3, where the saved script can be opened by the Run Script tool, but we want this script to be called by the Python program, then we need to generate an EXE program. Open the Compile Script to.exe tool and generate it as an EXE executable file. 4.16, Figure 4.16 Compile Script to.exe generate EXE program click "Browse" to select the Upfile.au3 file, click the "Convert" button to generate it as a upfile.exe program.
4, the following is through the automated test script call Upfile.exe program implementation upload.
#coding =utf-8from Selenium Import webdriverimport osdriver = Webdriver. Firefox () #打开上传功能页面file_path = ' file:///' + os.path.abspath (' upfile.html ') driver.get (File_path) #点击打开上传窗口driver. Find _element_by_name ("File"). Click () #调用upfile the. exe uploader Os.system ("D:\\upfile.exe") Driver.quit () |
The EXE program can be invoked and executed through the system () method of the Python OS module. Understanding the implementation of the upload process, the download is the same. Http://www.51testing.com/html/19/n-1265119.html
Turn: Selenium with AutoIt identification upload (download) detailed