selenium和AutoIt工具辅助下载和上传
上传
根据AutoIt Windows Info 所识别到的控件信息打开SciTE Script Editor编辑器,编写脚本。

;ControlFocus("title","text",controlID) Edit1=Edit instance 1
ControlFocus("选择要加载的文件", "","Edit1")
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set the File name text on the Edit field
//要上传的文件
ControlSetText("选择要加载的文件", "", "Edit1", "D:\\upload_file.txt")
Sleep(2000)
; Click on the Open button
ControlClick("选择要加载的文件", "","Button1");

ControlFocus()方法用于识别Window窗口。WinWait()设置10秒钟用于等待窗口的显示,其用法与WebDriver 所提供的implicitly_wait()类似。ControlSetText()用于向“文件名”输入框内输入本地文件的路径。这里的Sleep()方法与Python中time模块提供的Sleep()方法用法一样,不过它是以毫秒为单位,Sleep(2000)表示固定休眠2000毫秒。ControlClick()用于点击上传窗口中的“打开”按钮。
AutoIt的脚本已经写好了,可以通过菜单栏“Tools”-->“Go” (或按键盘F5)来运行一个脚本吧!注意在运行时上传窗口当前处于打开状态。
3、脚本运行正常,将其保存为upfile.au3,这里保存的脚本可以通过Run Script 工具将其打开运行,但我们的目的是希望这个脚本被Python程序调用,那么就需要将其生成exe程序。打开Compile Script to.exe工具,将其生成为exe可执行文件。如图4.16,

图4.16 Compile Script to.exe生成exe程序
点击“Browse”选择upfile.au3文件,点击“Convert”按钮将其生成为upfile.exe程序。
4、下面就是通过自动化测试脚本调用upfile.exe程序实现上传了。

#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.exe上传程序
os.system("D:\\upfile.exe") driver.quit()

; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set input focus to the edit control of Upload window using the handle returned by WinWait
ControlFocus("另存为","","Edit1")
Sleep(2000)
; Set the File name text on the Edit field
//下载的保存路径
ControlSetText("另存为", "", "Edit1", "d:\autoit-v3-setup")
Sleep(2000)
; Click on the Open button
ControlClick("另存为", "","Button1");
ControlFocus("另存为", "","Edit1");ControlFocus("title","text",controlID) Edit1=Edit instance 1
; Wait 10 seconds for the Upload window to appear
WinWait("[CLASS:#32770]","",10)
; Set input focus to the edit control of Upload window using the handle returned by WinWait
ControlFocus("另存为","","Edit1")
Sleep(2000)
; Set the File name text on the Edit field
ControlSetText("另存为", "", "Edit1", "d:\autoit-v3-setup")
Sleep(2000)
; Click on the Open button
ControlClick("另存为", "","Button1");
selenium和AutoIt工具辅助下载和上传的更多相关文章
- 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传
[源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...
- 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性
[源码下载] 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性 作者:webabcd 介 ...
- github下载和上传项目
git下载和上传项目 下载: git clone +地址 上传: 1.git init 在当前项目的目录中生成本地的git管理(多一个.git文件夹,为隐藏文件) 2.git add .(注意最后面有 ...
- python+selenium下载和上传文件
操作浏览器上传文件,先看代码 1 """ 2 * send_keys() 指定文件上传路径. 3 """ 4 from selenium i ...
- 在XShell中使用sz和rz命令下载和上传文件
借助XShell,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器 工具/原料 XShell CentOS 6.5 使用sz下载文件 1 输 ...
- 使用MFC提供的Http类下载和上传文件
1.下载文件 Download(const CString& strFileURLInServer, //待下载文件的URL const CString & strFileLocalF ...
- 2.4 利用FTP服务器下载和上传目录
利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...
- 2.3 利用FTP服务器下载和上传文件
二.利用FTP服务器的下载文件 from ftplib import FTP from os.path import exists def getfile(file,site,dir,user=(), ...
- 从Nexus私服下载和上传资源(一)
从私服中下载资源 首先要明确将资源下载到哪里 找到maven 配置文件settings.xml 文件,添加如下配置:1.添加镜像配置:将所有访问外网仓库的请求指向私服: <mirror> ...
随机推荐
- mysql 之优化
# ### part1 : sql语句优化 # (1) mysql 执行流程 客户端: 发送链接请求,然后发送sql语句 服务端: 1.连接层: 提供和客户端链接的服务 show processlis ...
- PyCharm注释中出现中文运行报错的解决办法
SyntaxError: Non-UTF-8 code starting with '..... 方法一:在文件首行加上 # -*- coding:utf-8 -*- 方法二:更改编码格式 File ...
- C++学习三 模板类出错总结(Missing template arguments before 'L')
一.模板类的说明 模板类有一个好处是可以放宽你输入的数据类型. 比如有这样的一个函数: int add(int x, int y) { return x+y; } 这个函数对于int类型的x,y才适合 ...
- python 实用小技巧
1. 列表 #以下三式等价 c = (a>b and a or b) c = a if a>b else b c = [b, a][a>b] 字符串拼接 ' + '.join('%s ...
- C++ 标准库 std::npos 表示 size_t 的最大值
参见:https://en.cppreference.com/w/cpp/algorithm/find std::npos 表示 size_t 的最大值,常用于对查找结果成功与否的判断. #inclu ...
- PointNet++作者的视频讲解文字版
转载请注明本文链接: https://www.cnblogs.com/Libo-Master/p/9759130.html PointNet: Deep Learning on Point Sets ...
- Node.js中的模块接口module.exports
在写node.js代码时,我们经常需要自己写模块(module).同时还需要在模块最后写好模块接口,声明这个模块对外暴露什么内容.实际上,node.js的模块接口有多种不同写法.在此做了个简单的总结. ...
- sublime3配置
1.sunblim3配置 一旦配置好了,如果换了一台电脑那直接将C:\Users\djx\AppData\Roaming\Sublime Text 3\Packages\User文件夹拷贝到新下载的s ...
- Pycharm2019.2.4专业版激活
Pycharm2019.2.4专业版激活 IDE是开发者创建程序时使用的的软件包,它通过简单的用户界面集成多个高度关联的组件,从而最大化提升编程体验和生产效率:本质上,IDE是一种改进代码创建.测试和 ...
- 【shell脚本】定时备份日志===logBackup.sh
定时备份日志 设置执行权限 [root@VM_0_10_centos shellScript]# chmod a+x logBackup,sh 脚本内容 [root@VM_0_10_centos sh ...