Selenium+python Automated 78-autoit parameterization and batch upload

Source: Internet
Author: User

Objective

AutoIt implementation of the file upload package as an. exe executable file, each time can only pass the fixed image, we actually test when we want to pass a different picture.
In this way, each time you call, you can add a file path parameter to the command line.

One, command-line parameters

1. Parameterize the passed-in parameters by AutoIt the command-line arguments:

```
MyProg.exe param1 "This is a string parameter" 99
```

In the script, command-line arguments can be obtained using the following variables:

```
$CmdLine [0]; = 3
$CmdLine [1]; = param1
$CmdLine [2]; = "This is a string parameter"
$CmdLine [3]; = 99
$CmdLineRaw; = ' param1 ' This is a string parameter ' 99 '
```
-$CmdLine [0] Gets the total number of command-line arguments, in the example above $cmdline[0]=3
-$CmdLine [1]~ $CmdLine [63] gets command-line arguments 1th through 63rd, which can fetch up to 63 parameters, but is normally sufficient
-$CmdLineRaw gets all the parameters that are not split, is a long string, in which case it is not limited to 63 parameters


2. After saving the following code as an. exe file (file name randomly: Cmdjpg.exe), execute once in CMD to see if it succeeds
```
Winactivate ("File Upload");
Controlsettext ("File Upload", "", "Edit1", $CmdLine [1]);
Sleep (2000);
Controlclick ("File Upload", "", "Button1");
```

3. Execute with Python code

"' Python

# The path of the image to be uploaded
File_path = "D:\\1.png"

# Execute AutoIt Upload file
Os.system ("C:\Users\Gloria\Desktop\cmdjpg.exe%s"% file_path) # your own local

```

Second, batch upload pictures

1. Method One: First put the image to be uploaded under a list, and then for loop

"' Python

# Put the images you need to upload into a list
All_png = ["D:\\1.png", "D:\\2.png", "D:\\3.png", "D:\\4.png"]

# cycle Click to upload images
For I in All_png:
# 1 O'Clock Open editor picture

# 2 O'Clock Open File Upload button

# Execute AutoIt Upload file
Os.system ("C:\Users\Gloria\Desktop\cmdjpg.exe%s"% i) # your own local. exe path
Time.sleep (3)

```

2. Method Two: To upload the image number, such as: 0.png, 1.png, 2.png this (starting from 0 numbering), put in the same directory, and then for loop

"' Python

# cycle Click to upload images
For I in range (4):
# 1 O'Clock Open editor picture

# 2 O'Clock Open File Upload button

# file name
file_name = "D:\\%s.png"% i # parameterized path name

# Execute AutoIt Upload file
Os.system ("C:\Users\Gloria\Desktop\cmdjpg.exe%s"% file_name) # your own local. exe path
Time.sleep (3)

```

Third, reference code

"' Python

1 #Coding:utf-82  fromSeleniumImportWebdriver3 Import Time4 ImportOS5 #load Profile Implementation-Free login6Profiledir = R'C:\Users\Gloria\AppData\Roaming\Mozilla\Firefox\Profiles\1x41j9of.default'  #the configuration file path of your own computer, do not copy my7Profile =Webdriver. Firefoxprofile (Profiledir)8Driver =Webdriver. Firefox (Profile)9Driver.implicitly_wait (30)TenDriver.get ("http://www.cnblogs.com/yoyoketang/") OneDriver.find_element_by_link_text ("New Essays"). Click () ATime.sleep (3) -  - #method One: Put the images that need to be uploaded to a list theAll_png = ["D:\\1.png","D:\\2.png","D:\\3.png","D:\\4.png"] -  -  forIinchall_png: -     #Click to open the editor picture +Driver.find_elements_by_css_selector ("Img.mceicon") [0].click () -Time.sleep (3) +     #locate all of the IFRAME and take a second Aiframe = Driver.find_elements_by_tag_name ('iframe') [1] at     #switch to the IFRAME - driver.switch_to_frame (IFRAME) -     #Click the File Upload button -Driver.find_element_by_name ('file'). Click () -Time.sleep (3) -     #Execute autoit Upload file in     PrintI -Os.system ("C:\Users\Gloria\Desktop\cmdjpg.exe%s"I#your own local. exe path toTime.sleep (3) +Driver.switch_to_default_content ()#cut back to the main page -  the  * ## Method Two: Cycle Click Upload Image $ #For I in range (4):Panax Notoginseng ## 1 O'Clock Open editor picture - #  the ## 2 O'Clock Open File Upload button + #  A ## file name the #file_name = "D:\\%s.png"% i # parameterized path name + #  - ## Execute AutoIt upload file $ #Os.system ("C:\Users\Gloria\Desktop\cmdjpg.exe%s"% file_name) # your own local. exe path $ #Time.sleep (3)

Selenium+python Automated 78-autoit parameterization and batch upload

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.