欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Pywinauto基礎教程之控件操作

 更新時間:2023年08月21日 10:55:18   作者:nikeylee  
這篇文章主要給大家介紹了關于Pywinauto基礎教程之控件操作的相關資料,pywinauto庫是一個用于在Windows上自動化操作的庫,文中通過代碼示例介紹的非常詳細,需要的朋友可以參考下

操作窗體中的控件

Pywinauto使用以下順序定位一個控件

1:控件的標題 title

2:控件的類名 friendly class

3:控件的標題加類名 title + friendly class

常用定位控件接口(重要)

# 通過層級查找控件相關方法
window(**kwargs) # 用于窗口的查找
child_window(**kwargs) # 可以無視層級的找后代中某個符合條件的元素===>【最常用】
parent() # 返回此元素的父元素,沒有參數(shù)
children(**kwargs) # 返回符合條件的子元素列表,支持索引,是BaseWrapper對象(或子類)
iter_children(**kwargs) # 返回子元素的迭代器,是BaseWrapper對象(或子類)
descendants(**kwargs) # 返回符合條件的所有后代元素列表,是BaseWrapper對象(或子類)
iter_children(**kwargs) # 符合條件后代元素迭代器,是BaseWrapper對象(或子類)---> 存疑,是iter_descendants?

常用屬性(重要)

# 常用的
class_name=None, # 類名
class_name_re=None, # 正則匹配類名
title=None, # 控件的標題文字,對應inspect中Name字段
title_re=None, # 正則匹配文字
control_type=None, # 控件類型,inspect界面LocalizedControlType字段的英文名
best_match=None, # 模糊匹配類似的title
auto_id=None, # inspect界面AutomationId字段,但是很多控件沒有這個屬性
# 不常用
parent=None,
process=None,# 這個基本不用,每次啟動進程都會變化
top_level_only=True,
visible_only=True,
enabled_only=False,
handle=None,
ctrl_index=None,
found_index=None,
predicate_func=None,
active_only=False,
control_id=None,
framework_id=None,
backend=None,

控件可用的方法屬性(重要)

# 以下幾個只支持窗口模式的控件
dlg.close() # 關閉界面
dlg.minimize() # 最小化界面
dlg.maximize() # 最大化界面
dlg.restore() # 將窗口恢復為正常大小,比如最小化的讓他正常顯示在桌面
dlg.get_show_state() # 正常0,最大化1,最小化2
dlg.menu_select() # 菜單欄,eg:app.window.menu_select(Edit -> Replace)
dlg.exists(timeout=None, retry_interval=None) # 判斷是否存在
        #timeout:等待時間,一般默認5s
        #retry_interval:timeout內重試時間
dlg.wait(wait_for, timeout=None, retry_interval=None) # 等待窗口處于特定狀態(tài)
dlg.wait_not(wait_for_not, timeout=None, retry_interval=None) # 等待窗口不處于特定狀態(tài),即等待消失
        # wait_for/wait_for_not:
            # * 'exists' means that the window is a valid handle
            # * 'visible' means that the window is not hidden
            # * 'enabled' means that the window is not disabled
            # * 'ready' means that the window is visible and enabled
            # * 'active' means that the window is active
        # timeout:等待多久
        # retry_interval:timeout內重試時間
        # eg: dlg.wait('ready')
# 鼠標鍵盤操作,只列舉了常用形式,他們有很多默認參數(shù)但不常用,可以在源碼中查看
ctrl.click_input() # 最常用的點擊方法,一切點擊操作的基本方法(底層調用只是參數(shù)不同),左鍵單擊,使用時一般都使用默認不需要帶參數(shù)
ctrl.right_click_input() # 鼠標右鍵單擊
ctrl.type_keys(keys, pause = None, with_spaces = False,) # 鍵盤輸入,底層還是調用keyboard.send_keys
        # keys:要輸入的文字內容
        # pause:每輸入一個字符后等待時間,默認0.01就行
        # with_spaces:是否保留keys中的所有空格,默認去除0
ctrl.double_click_input(button ="left", coords = (None, None)) # 左鍵雙擊
ctrl.press_mouse_input(coords = (None, None)) # 指定坐標按下左鍵,不傳坐標默認左上角
ctrl.release_mouse_input(coords = (None, None)) # 指定坐標釋放左鍵,不傳坐標默認左上角
ctrl.move_mouse_input(coords=(0, 0)) # 將鼠標移動到指定坐標,不傳坐標默認左上角
ctrl.drag_mouse_input(dst=(0, 0)) # 將ctrl拖動到dst,是press-move-release操作集合
# 控件的常用屬性
ctrl.children_texts() # 所有子控件的文字列表,對應inspect中Name字段
ctrl.window_text() # 控件的標題文字,對應inspect中Name字段
# ctrl.element_info.name
ctrl.class_name() # 控件的類名,對應inspect中ClassName字段,有些控件沒有類名
# ctrl.element_info.class_name
ctrl.element_info.control_type # 控件類型,inspect界面LocalizedControlType字段的英文名
ctrl.is_child(parent) # ctrl是否是parent的子控件
ctrl.legacy_properties().get('Value') # 可以獲取inspect界面LegacyIAccessible開頭的一系列字段,在源碼uiawraper.py中找到了這個方法,非常有用
# 控件常用操作
ctrl.draw_outline(colour='green') # 空間外圍畫框,便于查看,支持'red', 'green', 'blue'
ctrl.print_control_identifiers(depth=None, filename=None) # 以樹形結構打印其包含的元素,詳見打印元素
        # depth:打印的深度,缺省時打印最大深度。
        # filename:將返回的標識存成文件(生成的文件與當前運行的腳本在同一個路徑下)
ctrl.scroll(direction, amount, count=1,) # 滾動
        # direction :"up", "down", "left", "right"
        # amount:"line" or "page"
        # count:int 滾動次數(shù)
ctrl.capture_as_image() # 返回控件的 PIL image對象,可繼續(xù)使用其方法如下:
        # eg: ctrl.capture_as_image().save(img_path)
ret = ctrl.rectangle() # 控件上下左右坐標,(L430, T177, R1490, B941),可輸出上下左右
        # eg: ret.top=177
            # ret.bottom=941
            # ret.left=430
            # ret.right=1490

總結 

到此這篇關于Pywinauto基礎教程之控件操作的文章就介紹到這了,更多相關Pywinauto控件操作內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

相關文章

最新評論