python+uiautomation環境搭建
1.安裝python
下載下傳位址:https://www.python.org/
2.安裝uiautomation
安裝pip,步驟略(一般裝完python已經安裝)
打開cmd 執行:pip install uiautomation
3.基本操作
import subprocess
import uiautomation as automation
import time
def main():
subprocess.Popen('redcore.exe') #啟動浏覽器
time.sleep(1)
redWindow = automation.WindowControl(searchDepth = 1, ClassName = 'Chrome_WidgetWin_1') #取浏覽器handle
if not redWindow.Exists(0):
automation.Logger.WriteLine('未找到紅芯浏覽器,請重試!',automation.ConsoleColor.Yellow)
return
redWindow.ShowWindow(automation.ShowWindow.Maximize) #最大化浏覽器
redWindow.SetActive()
time.sleep(1)
# MenuOperation.menuOperation(redWindow) #操作浏覽器菜單
login = redWindow.TextControl(Name=u'未登入',searchDepth=3,searchWaitTime=10)
if login.Exists(5):
print("未登入!")
loginImages = redWindow.ImageControl(searchDepth=6,foundIndex=6)
time.sleep(1)
loginImages.Click()
print(loginImages)
time.sleep(2)
redWindow.SendKeys('{alt}{F4}')
time.sleep(2)
if __name__ == '__main__':
main()
input('全部運作完成')