第一范文网 - 专业文章范例文档资料分享平台

autoit快速开发指南

来源:用户分享 时间:2025/5/24 2:30:48 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

. .

12. IE操作

IE操作,不像GUI界面一样,通过AutoIt Window Info就能得到相关控件,进而获取控件句柄进行操作。 我们在操作IE网页时候,需要事先获取HTML页面中的相关Dom节点或元素,所以需要对HTML有一些了解。下面是一个简单的例子: $oIE = _IECreate (\_IEPropertySet ($oIE, \欢迎访问\$oForm = _IEFormGetObjByName ($oIE, \查找表单名 $oQuery1 = _IEFormElementGetObjByName ($oForm, \查找表单控件 _IEFormElementSetValue ($oQuery1, \赋值\给控件赋值 _IEFormSubmit ($oForm,1) ;点击提交表单请求 实例是一个简单操作,打开一个IE窗口,访问百度,然后在搜索网页表单,输入一个要查询的关键字,点击百度搜索。

一般网页很多超,对于这些的页面,都有很多的Dom节点嵌套,单纯的以对象名称不一定能够获取到某个操作的对象,这时需要从顶级Dom节点,一级一级缩小围,直到获取到最终操作对象节点,如下所示: $oIE = _IECreate (\$iFrame = _IEFrameGetObjByName ($oIE, \$oDiv = _IEGetObjById ($iFrame, \$ohrefArray = _IETagNameGetCollection ($oDiv,\For $oLink In $ohrefArray If $oLink.href = \ _IEAction($oLink,'click') ExitLoop EndIf Next 这里实例主要是从一个打开的浏览器窗口,获取名为iFrame的frame页面,然后获取其中为Id为divId的节点,进而,取到divId节点下的所有超对象,最后一个一个判断,找到某个url,点击超。 13. 自定义函数

把一些常用而相关逻辑的操作,抽离出来,独立成一个模块,供脚本调用,这就需要涉及到自定义函数。 用户可通过使用 Func...EndFunc 语句来自定义函数,函数中可以有Return返回值,也可以无,下面我们列出了一些常用的自定义函数,供参考: #include #Include #include #Include #Include #Include #include #include ;获取配置文件 . . .

. .

Func GetConfigFile()

Return String(\EndFunc

;根据给定的日期格式字符串转换成当前日期格式 Func ReplaceDateStr($DateStr) Select

Case StringInStr($DateStr,\

Return StringReplace($DateStr,\& DateMM() & DateDD())

Case StringInStr($DateStr,\

Return StringReplace($DateStr,\&\DateMM() &\

Case StringInStr($DateStr,\

Return StringReplace($DateStr,\&\DateMM() &\

Case StringInStr($DateStr,\ ;ABC代表英文的短月份格式,如1月=Jan Return StringReplace($DateStr,\& DateDD() &\

Case StringInStr($DateStr,\

Return StringReplace($DateStr,\ Case Else

Return $DateStr EndSelect EndFunc

;返回日期格式 Func DateYYYY()

Return String(YEAR) EndFunc

Func DateYY()

Return StringRight(String(YEAR),2) EndFunc

Func DateMM()

Return String(MON) EndFunc

Func DateDD()

Return String(MDAY) EndFunc

;写日志,截屏等操作 ;$fileName 日志文件

;$flag 操作标识 1为成功,0为失败 ;$logTxt 写入日志容,增加在行尾

Func WriteLog($fileName,$flag,$logTxt)

. . .

. .

;根据代理约定的相对目录

$File_dat= $fileName & \ $File_do = $fileName & \ $File_jpg = $fileName & \ ;截屏文件

_ScreenCapture_Capture($File_jpg) ;如果截屏失败,则启动画板

If FileExists($File_jpg) = 0 Then SaveImage($File_jpg) EndIf

;脚本执行结果文件

$file1=FileOpen($File_dat,2) FileWriteLine($file1, $flag) FileWriteLine($file1,$logTxt) FileClose($file1) ;状态文件

$file2=FileOpen($File_do,2) FileWriteLine($file2,\ FileClose($file2) EndFunc

;启动画图程序,将全屏截图保存为文件 ;$imgFile 文件保存路径 Func SaveImage($imgFile) Send(\

$picProcess = \ $pid = Run(\ $picWin = \未命名 - 画图\ $warnWin = \画图\ $saveWin = \保存为\ $imgFilePath = StringReplace(GetConfigFile(),\ If WinWait($picWin,\ WinActivate($picWin) Send(\

If WinActivate($warnWin) Then ControlClick($warnWin,\ WinMenuSelectItem($picWin,\文件\保存\ If WinWait($saveWin,\ WinActivate($saveWin)

ControlSetText($saveWin,\

ControlCommand($saveWin,\\(*.JPG;*.JPEG;*.JPE;*.JFIF)\

ControlClick($saveWin,\ If WinWait($saveWin,\已存在\

ControlClick($saveWin,\已存在\ EndIf

. . .

. .

EndIf

WinWait($imgFile)

If WinExists($imgFile) Then WinClose($imgFile) EndIf EndFunc

;判断窗口

;$win 窗口名称

;返回值 如果找存在返回1,否则返回0 Func ChkProgram($win) Dim $ret $ret=-1

If WinExists($win) Then $ret =1 Else

$ret =0 EndIf

Return $ret EndFunc

;判断程序进程

;$process 进程名称

;返回值 如果找存在返回1,否则返回0 Func ChkService($process) Dim $ret $ret=-1

$flag = ProcessExists($process) If $flag=0 Then $ret =0 Else

$ret =1 EndIf

Return $ret EndFunc

;根据给定的字符串匹配ListBox控件中的数据 ;$title 窗口标题

;$listBoxCmp ListBox控件

;$matchStr 匹配字符串.如果字符串以\连接,则匹配所有,如果字符串以\连接则匹配部分

;返回值 如果找到匹配的字符串返回1,否则返回0 Func MatchListBox($title,$listBoxCmp,$matchStr) Dim $ret,$count $ret=0 $num=0 $flag=1

. . .

. .

WinActivate($title)

If StringInStr($matchStr,'||')>0 Then

$array = StringSplit($matchStr, '||', 1) $flag=0 Else

$array = StringSplit($matchStr, '&&', 1) EndIf

$hWnd = ControlGetHandle($title,\ $count = _GUICtrlListBox_GetCount($hWnd) For $i=0 To $count-1

$hLabel = _GUICtrlListBox_GetText($hWnd, $i) If MatchStrArray($hLabel,$array) Then $num = $num + 1 If $flag Then

If $num = $array[0] Then $ret=1 ExitLoop EndIf Else

$ret=1 ExitLoop EndIf EndIf Next

Return $ret EndFunc

;匹配ListView控件字符串 ;$title 窗口标题

;$listViewCmp ListView控件 ;$cols 要查找的列,从0开始 ;$matchStr 匹配字符串

;返回值 如果找到匹配的字符串返回1,否则返回0

Func MatchListView($title,$listViewCmp,$cols,$matchStr) Dim $ret,$count,$rows $ret=0

WinActivate($title)

$rows = ControlListView($Title,\ $count=0

For $i=0 To $rows-1

$iText = ControlListView($Title,\ If StringInStr($iText,$matchStr)>0 Then $count=$count+1 EndIf Next

If $count=$rows Then $ret=1

. . .

搜索更多关于: autoit快速开发指南 的文档
autoit快速开发指南.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c4zgl06tcb947le14lopx1jxus0hl5300vw9_3.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top