上传

根据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()
 
 
下载  用工具盒编译成exe
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");

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");

最新文章

  1. ActiveMQ笔记(7):如何清理无效的延时消息?
  2. WinForm与WPF下跨线程调用控件
  3. 如果用css的border属性画一个三角形
  4. Selenium 面试题总结(乙醇Blog记录的面试题)
  5. 你真的了解NSNotificationCenter吗?
  6. 我的android学习经历7
  7. maven初学(三) SNAPSHOT
  8. Javascript网页摇一摇
  9. Leetcode | Parentheses 相关
  10. 开源搜索引擎Sphinx 中启动多个搜索进程的方法(转)
  11. js表格的输出
  12. 第四篇、Tomcat 集群
  13. poj 3304 找一条直线穿过所有线段
  14. eclipse安装ADT插件重启后不显示Android SDK Manager和Android Virtual Device Manager图标的一种解决办法
  15. exe可执行程序及堆栈分配(转载)
  16. 读Zepto源码之集合操作
  17. css3学习系列之移动
  18. ftp服务器搭建及简单操作
  19. CentOS 6.x 最小化安装推荐安装的依赖包和修改内核参数
  20. 20155324王鸣宇安装虚拟机+初次学习Linux的感想20155324

热门文章

  1. vscode使用formate格式化less遇到的坑
  2. [Go] golang实现mysql连接池
  3. 不能聚焦元素问题 WebDriverException: Message: unknown error: cannot focus element
  4. 初学JavaScript正则表达式(十三)
  5. gn gen ninja
  6. c# WF 第1节 创建winform程序
  7. 题解:T103342 Problem A. 最近公共祖先
  8. jQuery中的筛选(六)
  9. 鲜贝7.3--Xshell安装
  10. CF-1238 C.Standard Free2play