• autoit 脚本开发踩坑点


    原文

    1. 获取不到点击 <input type='file'/> 后弹出的window

    根本原因是 _IEAction 阻塞,见第4点
    解决办法:

    ;bad code
    $oIE = _IE_Example("form")
    $oT = _IEGetObjById($oIE, 'fileExample')
    _IEAction($oT,"click")
    WinWait("Choose File to Upload") ;等待不到弹出
    $hChoose = WinGetHandle("Choose File to Upload")
    
    ;good code
    $oIE = _IE_Example("form")
    $oT = _IEGetObjById($oIE, 'fileExample')
    MouseMove(_IEPropertyGet($oT, "screenx") + _IEPropertyGet($oT, "width") - 10, _
              _IEPropertyGet($oT, "screeny") + _IEPropertyGet($oT, "height")/2)
    MouseClick("left")
    WinWait("Choose File to Upload")
    

    2. send 需要切换英文输入法

    如果没有切换英文输入法,会出现中文输入法候选框
    如果能用ControlSend,就不推荐用send,如果非要用send,可以切换输入法为英文再send.

    ;设置指定窗口为英文输入法
    $hWnd = WinGetHandle("[ACTIVE]");$hWnd 为目标窗口句柄,这里设置的是当前活动窗口
    $ret = DllCall("user32.dll", "long", "LoadKeyboardLayout", "str", "08040804", "int", 1 + 0)
    DllCall("user32.dll", "ptr", "SendMessage", "hwnd", $hWnd, "int", 0x50, "int", 1, "int", $ret[0])        
    Send('nh')
    

    3. 有时 IE对象 需要重新获取,以便刷新一下值,否则为null

    原因未知

    4. _IEAction($btnsave,"click") 会阻塞,直到事件完成

    所以使用 _IEAction 触发事件时,如果事件里有 alert 之类的弹窗,程序会一直停留在这一句,导致无法继续。所以即便在后面写了 WinWait 等待弹窗的句子,也无济于事。

    推荐使用鼠标光标去点击这个按钮,再 WinWait弹窗

    5. 日志中的不解之谜

    程序运行时日志里,常有下面的 COM Error ,但没有显示异常的行数。结合前后逻辑也没能分析出问题。

    另外 scriptline 总是显示 -1 的原因竟然是,编译成exe后,脚本获取不到行数。行数scriptline只会在开发时使用 f5 调试中有效 。(出自链接1连接2

    2021-06-30 14:53:03:AutoItCOM Test , We intercepted a COM Error !
    2021-06-30 14:53:03:err.description is: 	
    2021-06-30 14:53:03:err.windescription:	发生意外。
    2021-06-30 14:53:03:err.number is: 	80020009
    2021-06-30 14:53:03:err.lastdllerror is: 	0
    2021-06-30 14:53:03:err.scriptline is: 	-1
    2021-06-30 14:53:03:err.source is: 	
    2021-06-30 14:53:03:err.helpfile is: 	
    2021-06-30 14:53:03:err.helpcontext is: 	0
    2021-06-30 14:53:03:AutoItCOM Test , We intercepted a COM Error !
    2021-06-30 14:53:03:err.description is: 	
    2021-06-30 14:53:03:err.windescription:	发生意外。
    2021-06-30 14:53:03:err.number is: 	80020009
    2021-06-30 14:53:03:err.lastdllerror is: 	0
    2021-06-30 14:53:03:err.scriptline is: 	-1
    2021-06-30 14:53:03:err.source is: 	
    2021-06-30 14:53:03:err.helpfile is: 	
    2021-06-30 14:53:03:err.helpcontext is: 	0
    
  • 相关阅读:
    看了关于全职女性的文字,我想到了一些事情
    通过一个大型项目来学习分布式算法(6)
    IO模式——同步(堵塞、非堵塞)、异步
    湖南省第九届大学生计算机程序设计竞赛 高桥和低桥
    为什么我的ECSHOP出现报错改正确了还是没有反应?
    wxWidgets刚開始学习的人导引(2)——下载、安装wxWidgets
    1096. Consecutive Factors (20)
    POJ 2955 Brackets
    (转载)单调栈题目总结
    20140708郑州培训第二题Impossible Game
  • 原文地址:https://www.cnblogs.com/ohzxc/p/15759343.html
Copyright © 2020-2023  润新知