Selenium upload (download) detailed with AutoIt

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/fnng/p/4188162.html

AutoIt is currently the latest version of the V3, a freeware that uses a similar basic scripting language, designed for automated operations in the Windows GUI (graphical user interface). It uses analog keyboard keys, mouse Movement and window/control combinations to automate tasks.

Official website:https://www.autoitscript.com/site/

Download the AutoIt from the website and install it, and you will see the directory in Figure 4.13 in the menu:

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, opened in a browser, with the following effect:

Following the operation 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

Figure 4.15 AutoIt Windows Info recognizes the Open button control

4.14, 4.15, get the following information by AutoIt Windows info.

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 1ControlFocus ("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 (200 0); 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 generating EXE program

Click "Browse" to select the Upfile.au3 file and 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) # Click to open the Upload window 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.

Selenium upload (download) detailed with AutoIt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.