前段時間,我一直認為,通過AutoIt進行自動化操作,也只有幾個方法可以用,它們只是controlClick, controlsend等如下圖:
我一直認為,AutoIt的所有的GUI 方法,都是用來創建界面使用的。
今天,開發找我,讓我把他的一個GUI頁面上所有的資源獲取下來:
頁面上一個ListView中,一共有大約70個list,我現在需要遍歷這70個list,然后當該list獲取焦點的時候,右鍵點擊,然后在彈出框中點擊第二個選項,從而保存圖片?
我一直期待能找到一個函數,比喻:ControlGetFocusPos,可是沒有這個函數,mouseGetPos函數只能獲取鼠標所在的位置,google搜索也得不到想要的答案。
問題最終還是被我解決了:
1. 遍歷每個list的位置坐標X, Y;
2. 在該坐標上右鍵點擊;
3. 用鍵盤上的Down和Enter鍵,點擊彈出框的第二個按鈕;
4. 保存相應資源
具體代碼如下:
#include <GuiListView.au3> ;獲取窗口句柄 $handle = WinGetHandle(".NET Reflector 6") WinActivate($handle) ;獲取控件句柄; $control = ControlGetHandle($handle,"","WindowsForms10.SysListView32.app.0.232467a_r11_ad11") ;獲取列表中List數目 $count = ControlListView($handle,"",$control,"GetItemCount") for $i = 1 to 10 ;獲取位置信息 $x = _GUICtrlListView_GetItemPositionX($control, $i-1) $y = _GUICtrlListView_GetItemPositionY($control, $i-1) ControlClick($handle,"", $control,"right",1, $x, $y) ControlSend($handle,"",$control,"{down 2}{enter}") WinWait("Save As") WinWaitActive("Save As") $handle2 = WinGetHandle("Save As") ControlSetText($handle2,"", "Edit1", "C:\Users\chenpassion\Desktop\Autoit\pic\" & $i & ".png") ControlClick($handle2,"","Button1") WinWaitClose("Save As") ControlSend($handle,"",$control,"{down}") Next
看來又有得深入學習了!
_GUICtrl***函數,是非常強大的,可以做更多的識別頁面元素,操作Windows GUI 控件。