Web Automation 9-selenium. Windows uploads files

Source: Internet
Author: User

AutoIt Installation

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.

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 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.

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-8

From selenium import Webdriver

Import OS

Driver = Webdriver. Firefox ()

#打开上传功能页面

File_path = ' file:///' + os.path.abspath (' upfile.html ')

Driver.get (File_path)

#点击打开上传窗口

Driver.find_element_by_name ("File"). Click ()

#调用upfile the. exe upload program

Os.system ("D:\\upfile.exe")

Driver.quit ()

Web Automation 9-selenium. Windows uploads files

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.