通过autoit上传文件
结合python + selenium实现上传
下载 autoit
![](https://img-blog.csdnimg.cn/img_convert/c6b48e27a6f95d5405f11c128d00809c.webp?x-oss-process=image/format,png)
下载 ZIP 压缩包
![](https://img-blog.csdnimg.cn/img_convert/98b8e36e403766237336c00afb69e811.webp?x-oss-process=image/format,png)
定位工具
需要打开文件上传窗口
![](https://img-blog.csdnimg.cn/img_convert/4dfc8aaccaa9a0a99660189eda8e6164.webp?x-oss-process=image/format,png)
文件上传
打开定位工具
![](https://img-blog.csdnimg.cn/img_convert/564547f7d465092a37ecbde792a15139.webp?x-oss-process=image/format,png)
定位工具
操作步骤:
点击小风扇拖拽至文件上传窗口处
![](https://img-blog.csdnimg.cn/img_convert/1a871e3ff63970e82d2831375748a1a0.webp?x-oss-process=image/format,png)
点击第一步中的小风扇,拖拽至第二步
点击小风扇拖拽至打开按钮处
![](https://img-blog.csdnimg.cn/img_convert/4161aaa9178be1e32553ad41d382f113.webp?x-oss-process=image/format,png)
点击第一步中的小风扇,拖拽至第二步
从上面的两张图中得到一下信息:
文件名输入框的Class:Edit
Instance:1
ClassnameNN:Edit1
打开按钮的Class:Button
Instance:1
ClassnameNN:Button1
编写脚本代码
![](https://img-blog.csdnimg.cn/img_convert/cf5e4bf1b6152fbf82b6c07e05946512.webp?x-oss-process=image/format,png)
打开编辑器,编写脚本
修改字符编码
![](https://img-blog.csdnimg.cn/img_convert/d76faeb462496250764d91a9d162c098.webp?x-oss-process=image/format,png)
解决中文乱码问题
打开文本输入框
等待10s,上传窗口出现
文本框输入文件名
单击打开按钮
ControlFocus("打开","","Edit1")
WinWait("[Class:#32770]","",10)
ControlSettext("","","Edit1","C:\Users\lh234\Documents\teaching_plan\Python\Demo\Photo\img.png")
Sleep(2000)
ControlClick("打开","","Button1")
Sleep(2000)
保存文件,文件名为:upload.au3
调试运行一下
运行时打开文件上传窗口
![](https://img-blog.csdnimg.cn/img_convert/139eead35494e94905041177fe15c4e8.webp?x-oss-process=image/format,png)
👉Tools → Go
脚本运行正常后打开 Aut2exe 工具将其编译成 exe 可执行文件
![](https://img-blog.csdnimg.cn/img_convert/e7672b0a4170c0444c39327d118311eb.webp?x-oss-process=image/format,png)
打开该工具
点击 Browse 选择 upload.au3 文件,点击 Convert 按钮将其生成为upload.exe程序
![](https://img-blog.csdnimg.cn/img_convert/185d7c399800dd259a75b02fd1db9eb6.webp?x-oss-process=image/format,png)
👉 Browse 选择之前编辑的脚本文件 upload.au3
点击确定
![](https://img-blog.csdnimg.cn/img_convert/962aac9603069c1c481c348fd2c34d5e.webp?x-oss-process=image/format,png)
👉 Convert 生成 exe可执行文件
python代码
driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get("https://www.baidu.com/")
driver.maximize_window()
# 点击相机按钮
driver.find_element(By.CSS_SELECTOR, ".soutu-btn").click()
sleep(1)
# 点击选择文件
driver.find_element(By.XPATH, "//div[@class='upload-wrap']").click()
sleep(2)
# 脚本名称:upload.au3
# 脚本内容:
# ControlFocus("打开","","Edit1")
# WinWait("[Class:#32770]","",10)
ControlSettext("","","Edit1","C:\Users\lh234\Documents\teaching_plan\Python\Demo\Photo\img.png")
# Sleep(2000)
# ControlClick("打开","","Button1")
# Sleep(2000)
# os模块的system()方法可以调用exe程序并执行
os.system(r"C:\Users\lh234\Downloads\autoit-v3\install\SciTe\upload.exe")
sleep(5)
driver.quit()