上传

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

selenium和AutoIt工具辅助下载和上传的更多相关文章

  1. 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传

    [源码下载] 重新想象 Windows 8 Store Apps (66) - 后台任务: 下载和上传 作者:webabcd 介绍重新想象 Windows 8 Store Apps 之 后台任务 后台 ...

  2. 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性

    [源码下载] 重新想象 Windows 8.1 Store Apps (91) - 后台任务的新特性: 下载和上传的新特性, 程序启动前预下载网络资源, 后台任务的其它新特性 作者:webabcd 介 ...

  3. github下载和上传项目

    git下载和上传项目 下载: git clone +地址 上传: 1.git init 在当前项目的目录中生成本地的git管理(多一个.git文件夹,为隐藏文件) 2.git add .(注意最后面有 ...

  4. python+selenium下载和上传文件

    操作浏览器上传文件,先看代码 1 """ 2 * send_keys() 指定文件上传路径. 3 """ 4 from selenium i ...

  5. 在XShell中使用sz和rz命令下载和上传文件

    借助XShell,使用linux命令sz可以很方便的将服务器上的文件下载到本地,使用rz命令则是把本地文件上传到服务器 工具/原料   XShell CentOS 6.5 使用sz下载文件   1 输 ...

  6. 使用MFC提供的Http类下载和上传文件

    1.下载文件 Download(const CString& strFileURLInServer, //待下载文件的URL const CString & strFileLocalF ...

  7. 2.4 利用FTP服务器下载和上传目录

    利用FTP服务器下载目录 import os,sys from ftplib import FTP from mimetypes import guess_type nonpassive = Fals ...

  8. 2.3 利用FTP服务器下载和上传文件

    二.利用FTP服务器的下载文件 from ftplib import FTP from os.path import exists def getfile(file,site,dir,user=(), ...

  9. 从Nexus私服下载和上传资源(一)

    从私服中下载资源 首先要明确将资源下载到哪里 找到maven 配置文件settings.xml 文件,添加如下配置:1.添加镜像配置:将所有访问外网仓库的请求指向私服: <mirror> ...

随机推荐

  1. 9-SQL视图

    (1) 如何创建,更新和删除视图         视图作为一张虚拟表,帮我们封装了底层与数据表的接口.它相当于是一张表或多张表的数据结果集.视图的这一特点,可以帮我们简化复杂的 SQL 查询,比如在编 ...

  2. Django—常见问题解决

    让Django项目运行允许外部访问 1.将python manage.py runserver 改为 python manage.py runserver 0.0.0.0:80 或者 python m ...

  3. Python的 Datetime 、 Logging 模块

    Datetime模块 datetime是python处理时间和日期的标准库 类名 date类        日期对象,常用的属性有 year . month . day time类        时间 ...

  4. nfs共享文件系统

    NFS服务简介 NFS 就是 Network FileSystem 的缩写,最早之前是由sun 这家公司所发展出来的. 它最大的功能就是可以透过网络,让不同的机器.不同的操作系统.可以彼此分享个别的档 ...

  5. vue.nextTick()方法的使用详解

    什么是Vue.nextTick()??   定义:在下次 DOM 更新循环结束之后执行延迟回调.在修改数据之后立即使用这个方法,获取更新后的 DOM. 所以就衍生出了这个获取更新后的DOM的Vue方法 ...

  6. PAT 1145 1078| hashing哈希表 平方探测法

    pat 1145: 参考链接 Quadratic probing (with positive increments only) is used to solve the collisions.:平方 ...

  7. c# 第32节 类的继承

    本节内容: 1:为什么要继承 2:继承特点 3:继承的实现 4:子类传统构造,与base构造 1:为什么要继承 2:继承特点 什么是继承: 继承就是子类包含父类的数据结构和行为方式, 包括字段.属性. ...

  8. Pwn-pwn-100

    题目地址http://www.whalectf.xin/files/2779dd8a2562a1d5653c5c6af9791711/binary_100 32位 ,没有防护 上IDA 很简单的栈溢出 ...

  9. day81_10_30redis的简单操作。

    一.启动redis 在启动redis中可以持续的启动redis服务端,启动的服务端即使被关掉也不会停止服务: >: redis-server & 在客户端连接刚刚启动的redis服务端: ...

  10. Loadrunner|录制脚本时出现乱码的解决方式

    1.进入options 2. 保存后,再录制到脚本就不会有乱码了!