Python uses Webdriver to process uploading files (using AutoIt)

Source: Internet
Author: User
Tags python script

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)

Related Article

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.