# pywinauto.application 模塊
application(應用程序)模塊是用戶首先使用的主要模塊。
開始自動化應用程序時,必須初始化Application類的實例. 然后你必需使用 [`Application.start()`](#pywinauto.application.Application.start "pywinauto.application.Application.start") 啟動應用程序或使用 [`Application.connect()`](#pywinauto.application.Application.connect "pywinauto.application.Application.connect")連接到已啟動的應用程序。
獲得Application實例后,您可以使用以下方法之一訪問該應用程序中的對話框。
~~~
dlg = app.YourDialogTitle
dlg = app.child_window(title="your title", classname="your class", ...)
dlg = app['Your Dialog Title']
~~~
類似地,一旦你有了一個對話框,你就可以用幾乎完全相同的方式從該對話框中獲得一個控件。
~~~
ctrl = dlg.YourControlTitle
ctrl = dlg.child_window(title="Your control", classname="Button", ...)
ctrl = dlg["Your control"]
~~~
>[info]注意
對于控件和對話框的屬性訪問,您不必完全擁有控件的標題,它可以與可用的對話框或控件進行最佳匹配。
>[info]另請參見
`pywinauto.findwindows.find_elements()`表示可以同時傳遞給: `Application.window()` 和`WindowSpecification.child_window()`的關鍵字參數
>[success]*異常* `pywinauto.application.AppNotConnected`
基類: `Exception`
應用程序尚未與進程相關聯
>[success]*異常* `pywinauto.application.AppStartError`
基類: `Exception`
啟動應用程序時出現問題
>[success]*類* `pywinauto.application.Application(backend='win32', datafilename=None)`
基類: `object`
代表一個應用程序
>`__getattribute__(attr_name)`
找到應用程序的指定對話框
>`__getitem__(key)`
查找應用程序的指定對話框
>`GetMatchHistoryItem(index)`
不應該使用 - 應用程序數據實現的一部分
>`WriteAppData(filename)`
不應該使用 - 應用程序數據實現的一部分
>`active()`
為應用程序的活動窗口返回WindowsSpecification
>`connect(**kwargs)`
連接到已在運行的進程
該動作僅根據一個參數執行
**參數**:
* process – 目標的進程ID
* handle – 目標的窗口句柄
* path – 用于啟動目標的路徑
* timeout – 進程啟動超時(如果指定了路徑,則與此相關)
>[info]另請參見
[`pywinauto.findwindows.find_elements()`](pywinauto.findwindows.html#pywinauto.findwindows.find_elements "pywinauto.findwindows.find_elements") -也可以使用關鍵字參數來代替**process**、**handle**或**path**
>`cpu_usage(interval=None)`
返回指定秒數內的CPU使用率百分比
>`is64bit()`
如果運行進程為64位,則返回True
>`is_process_running()`
檢查進程是否正在運行。
可以在啟動/連接之前調用。
如果進程正在運行,則返回true;否則返回false。
>`kill(soft=False)`
嘗試關閉(可選)并終止應用程序
對話框可能會彈出,要求保存數據-但應用程序仍將被終止-您將無法單擊按鈕。只有當可以像在任務管理器中那樣終止進程時,才應該使用此選項。
>`start(cmd_line, timeout=None, retry_interval=None, create_new_console=False, wait_for_idle=True, work_dir=None)`
按cmd_line指定啟動應用程序
>`top_window()`
返回應用程序當前頂部窗口的WindowsSpecification
>`wait_cpu_usage_lower(threshold=2.5, timeout=None, usage_interval=None)`
等待,直到進程CPU使用率百分比小于指定的閾值
>`wait_for_process_exit(timeout=None, retry_interval=None)`
等待進程退出,直到超時
如果達到超時,則引發TimeoutError異常
>`window(kwargs)`
返回應用程序的窗口
您可以指定與findwindows.find_windows相同的參數。 它將添加process參數以確保窗口來自當前進程。
>[info]參考[`pywinauto.findwindows.find_elements()`](pywinauto.findwindows.html#pywinauto.findwindows.find_elements "pywinauto.findwindows.find_elements") 用于完整的參數描述.
>`windows(kwargs)`
返回應用程序的包裝頂級窗口列表
>[success] `pywinauto.application.AssertValidProcess(process_id)`
如果process_id不是有效的進程ID,則引發ProcessNotFound異常
>[success] *異常* `pywinauto.application.ProcessNotFoundError`
基類: `Exception`
找不到該進程
>[success] *類* `pywinauto.application.WindowSpecification(search_criteria)`
基類: `object`
查找窗口或控件的規范
使用時會解析窗口。您還可以等待窗口的存在或不存在
>`__getattribute__(attr_name)`
此類的屬性訪問
如果我們已經有對話框和控件的標準,那么解析控件并返回請求的屬性。
如果我們只有對話框的標準,但請求的屬性是DialogWrapper的屬性,則解析對話框并返回請求的屬性。
否則將功能委托給`__getitem __()` - 它為控件設置了適當的標準。
>`__getitem__(key)`
允許通過項目訪問權限訪問對話框/控件
比如本次允許:
~~~
app['DialogTitle']['ControlTextClass']
~~~
用于訪問對話框和控件。
這和`__getattribute __()`都使用HowTo文檔中概述的規則。
>`WAIT_CRITERIA_MAP = {'exists': ('exists',), 'visible': ('is_visible',), 'enabled': ('is_enabled',), 'ready': ('is_visible', 'is_enabled'), 'active': ('is_active',)}`
>`child_window(criteria)`
添加控件的條件
解決此窗口規范后,將使用它來匹配控件。
>`dump_tree(depth=None, filename=None)`
打印'標識符'
將控件及其子代的標識符打印到**depth**(如果**None**,則打印整個子樹)。
>[info]注意
通過此方法打印的標識符已經是唯一的。 因此,如果您有2個編輯框,則它們的標識符中不會同時顯示“Edit”。 事實上,第一個可以被稱為“Edit”,“Edit0”,“Edit1”,第二個應該被稱為“Edit2”。
>`exists(timeout=None, retry_interval=None)`
檢查窗口是否存在,如果控件存在則返回True
參數:
timeout – 等待控件存在的最長時間。默認為Timings.exists_timeout
retry_interval – 檢查控件是否存在此秒數。默認為Timings.exists_retry
>`print_control_identifiers(depth=None, filename=None)`
打印'標識符'
將控件及其子代的標識符打印到**depth**(如果**None**,則打印整個子樹)。
>[info]注意
通過此方法打印的標識符已經是唯一的。 因此,如果您有2個編輯框,則它們的標識符中不會同時顯示“Edit”。 事實上,第一個可以被稱為“Edit”,“Edit0”,“Edit1”,第二個應該被稱為“Edit2”。
>`print_ctrl_ids(depth=None, filename=None)`
打印'標識符'
將控件及其子代的標識符打印到**depth**(如果**None**,則打印整個子樹)。
>[info]注意
通過此方法打印的標識符已經是唯一的。 因此,如果您有2個編輯框,則它們的標識符中不會同時顯示“Edit”。 事實上,第一個可以被稱為“Edit”,“Edit0”,“Edit1”,第二個應該被稱為“Edit2”。
>`wait(wait_for, timeout=None, retry_interval=None)`
等待窗口處于特定狀態。
參數:
* **wait_for** –等待窗口進入的狀態。它可以是以下任何狀態,也可以按空格組合狀態。 'exists'表示窗口是有效的句柄。 'visible'表示窗口未隱藏。 'enabled'表示窗口未被禁用。 'ready'表示窗口可見并已啟用。 'active'表示窗口處于活動狀態
* **timeout** – 如果窗口在此秒數后未處于適當狀態,則引發pywinauto.timings.TimeoutError()。 默認: pywinauto.timings.Timings.window_find_timeout.
* **retry_interval** – 每次重試之間的等待時間。默認: pywinauto.timings.Timings.window_find_retry.
等待對話存在,已準備就緒,已啟用且可見的示例:
~~~
self.Dlg.wait("exists enabled visible ready")
~~~
>[info]另請參見
`WindowSpecification.wait_not()`
`pywinauto.timings.TimeoutError()`
>`wait_not(wait_for_not, timeout=None, retry_interval=None)`
等待窗口不處于特定狀態。
參數:
* wait_for_not –等待窗口不在的狀態。它可以是以下任何狀態,也可以通過空格組合狀態。 'exists'表示窗口是有效的句柄。 'visible'表示窗口未隱藏。 'enabled'表示窗口未被禁用。 'ready'表示窗口可見并已啟用。 'active'表示窗口處于活動狀態
* timeout – 如果窗口在此秒數之后還處于狀態,則引發pywinauto.timings.TimeoutError()。 默認: pywinauto.timings.Timings.window_find_timeout.
* retry_interval – 每次重試之間的等待時間。默認: pywinauto.timings.Timings.window_find_retry.
等待對話框未就緒、未啟用或不可見的示例:
~~~
self.Dlg.wait_not("enabled visible ready")
~~~
>[info]另請參見
`WindowSpecification.wait()`
`pywinauto.timings.TimeoutError()`
>`window(criteria)`
child_window()的棄用別名
>`wrapper_object()`
允許調用代碼獲取HwndWrapper對象
>[success]`pywinauto.application.assert_valid_process(process_id)`
如果process_id不是有效的進程ID,則引發ProcessNotFound錯誤
>[success] `pywinauto.application.process_from_module(module)`
用路徑模塊返回正在運行的進程
>[success] `pywinauto.application.process_get_modules()`
將進程列表作為元組返回(pid,exe_path)
>[success] `pywinauto.application.process_module(process_id)`
返回此進程的字符串模塊名稱
- 什么是Pywinauto
- 入門指南
- 如何
- 等待長時間操作
- 遠程執行指南
- 每種不同控制類型可用的方法
- 貢獻者
- 開發筆記
- 待辦項目
- 更新日志
- 基本用戶輸入模塊
- pywinauto.mouse
- pywinauto.keyboard
- 主要用戶模塊
- pywinauto.application
- pywinauto.findbestmatch
- pywinauto.findwindows
- pywinauto.timings
- 特定功能
- pywinauto.clipboard
- pywinauto.win32_hooks
- 控件參考
- pywinauto.base_wrapper
- pywinauto.controls.hwndwrapper
- pywinauto.controls.menuwrapper
- pywinauto.controls.common_controls
- pywinauto.controls.win32_controls
- pywinauto.controls.uiawrapper
- pywinauto.controls.uia_controls
- Pre-supplied Tests
- pywinauto.tests.allcontrols
- pywinauto.tests.asianhotkey
- pywinauto.tests.comboboxdroppedheight
- pywinauto.tests.comparetoreffont
- pywinauto.tests.leadtrailspaces
- pywinauto.tests.miscvalues
- pywinauto.tests.missalignment
- pywinauto.tests.missingextrastring
- pywinauto.tests.overlapping
- pywinauto.tests.repeatedhotkey
- pywinauto.tests.translation
- pywinauto.tests.truncation
- 后端內部實施模塊
- pywinauto.backend
- pywinauto.element_info
- pywinauto.win32_element_info
- pywinauto.uia_element_info
- pywinauto.uia_defines
- 內部模塊
- pywinauto.controlproperties
- pywinauto.handleprops
- pywinauto.xml_helpers
- pywinauto.fuzzydict
- pywinauto.actionlogger
- pywinauto.sysinfo
- pywinauto.remote_memory_block