上传

根据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. linux基础学习(二)ls命令以及文件访问权限例(-rw-r-r--)

    ls命令 |命令选项|作用| |:-----:|:----:| |ll| 显示文件得详细信息| |ls -a |显示文件和隐藏文件| |ls -t|以文件和目录的更改时间排序| |ls -m|用&qu ...

  2. openssl rsa加密,解密以及X509证书的使用

    Openssl的相关使用 生成证书 生成证书见:使用 openssl 生成证书 代码实现 Cert.h #ifndef _CERT_H #define _CERT_H ///header files ...

  3. CodeForces 1260D(二分+贪心+差分)

    题意 https://vjudge.net/problem/CodeForces-1260D 有m个士兵,t秒,你要带尽可能多的士兵从0去n+1,且他们不能被杀死.路上有一些陷阱,陷阱d[i]会杀死能 ...

  4. CodeForces-1257D (贪心+双指针)

    题意 https://vjudge.net/problem/CodeForces-1257D 你需要操作m个英雄去打败n只怪物,每个英雄的力量值为pi,可以打败si只怪物:每只怪物的力量值为ai. 当 ...

  5. 在宿主机上执行docker容器内部的shell或程序

    为了避免反复进入docker容器内部操作,可以将一系列容器内部的指令由宿主机来操作完成. 在宿主机(作者主机为windows7)上执行centos容器(name为centos-1)中/usr目录下的“ ...

  6. Mybatis-plus中的常用注解

    @TableName:数据库表相关 @TableId:表主键标识 @TableField:表字段标识 @TableLogic:表字段逻辑处理注解(逻辑删除) @TableId(type= IdType ...

  7. 鲜贝7.3--navicat破解

    Navicat for MySQL 安装软件和破解补丁: 链接:https://pan.baidu.com/s/1yy5JkrXk5NV129wzkzntqw 提取码:htc2 1.安装Navicat ...

  8. springcloud源码分析(一)之采用redis实现注册中心

    注册中心 在分布式架构中注册中心起到了管理各种服务功能包括服务的注册.发现.熔断.负载.降级等功能,在分布式架构中起到了不可替代的作用.常见的注册中心有eureka,zookeeper等等,在spri ...

  9. [2019BUAA软工助教]助教学期总结

    [2019BUAA软工助教]助教学期总结 一.量化自评 线上 博客点评:https://www.cnblogs.com/ChildishChange/MyComments.html 共 106 条 博 ...

  10. LeetCode 94:二叉树的中序遍历 Binary Tree Inorder Traversal

    题目: 给定一个二叉树,返回它的中序 遍历. Given a binary tree, return the inorder traversal of its nodes' values. 示例: 输 ...