1.AUTO源碼:這是一個漂亮的小姐姐給我的源碼,可以直接使用它來生成exe文件
;first make sure the number of arguments passed into the scripts is more than 1
If $CmdLine[0]<2 Then Exit EndIf ;if parmas num <2 ,then break
;$CmdLine[0] ;參數的數量
;$CmdLine[1] ;第一個參數 (腳本名稱後面)
;$CmdLine[2] ;第二個參數
;都是從cmd傳入參數
handleUpload($CmdLine[1],$CmdLine[2])
;定義上傳函數,有兩個參數,第一個是瀏覽器名字,第二參數是文件路徑
Func handleUpload($browser, $uploadfile)
Dim $title ;定義一個title變量
;根據彈窗的title來判斷是什麼瀏覽器
If $browser="ie" Then ; 代表IE瀏覽器
$title="選擇要加載的文件"
ElseIf $browser="chrome" Then ; 代表谷歌瀏覽器
$title="打開"
ElseIf $browser="firefox" Then ; 代表火狐瀏覽器
$title="文件上傳"
EndIf
if WinWait($title,"",4) Then ;等待彈出出現,最大等待時間是4秒
WinActivate($title) ;找到彈出窗口之後,激活當前窗口
ControlSetText($title,"","Edit1",$uploadfile) ;把文件路徑放入輸入框,此”Edit1“是用FinderTool獲取到的
ControlClick($title,"","Button1") ;點擊保存或者打開或者上傳按鈕,此“Button1”使用FinderTool獲取到的
Else
Return False
EndIf
EndFunc
2.python文件:
# author:閆振興
# contact: [email protected]
# datetime:2020/4/19 10:42
# software: PyCharm
"""
文件說明:
"""
# encoding:utf-8
import os
import time
class Upload():
def handleUpload(self, browser, filePath):
executeFile = r"E:\workspace\pyworkspace\UI_DFNFRZZL\TestTools\upload.exe"
command = "\"" + executeFile + "\"" + " " + "\"" + browser + "\"" + " " + "\"" + filePath + "\""
try:
os.popen(command)
except Exception as e:
time.sleep(5)
print(e, "附件上傳失敗")