在python3中按标题选择窗口

2024-05-16 02:11:49 发布

您现在位置:Python中文网/ 问答频道 /正文

这是一个有趣的!在

使用pywinauto时,我试图关闭软件中的弹出窗口,因为它是有条件的。在

def get_window():
    app = pywinauto.application.Application(backend="uia")
    app.connect(path='gofer.exe')
    #app.Properties.print_control_identifiers()
    trade = app.window(best_match='Warning:')
    # trade.wrapper_object().close
    print(trade)
    if trade == 'Warning:':
        print("You see the Window")
        # press enter key to displace
        # start next action
    else:
        print("Naw, No window bro")
        # Log to file 
        pass

印刷品(贸易)的输出为:

^{pr2}$

所以我知道这至少是有效的,但不是去我想去的地方。这个警告是一个弹出的窗口,根据spy++有一个警告的标题,但是我无法打印窗口数据。。。虽然窗口是一个弹出窗口,但它不是一个吐司弹出窗口,如果这有区别的话。这是一个窗口。在

属性打印一个只引用主程序和对话框窗口提示的dict,但从不指定属性。即使在搜索主程序标题时,我也无法使其正确工作。在

提前谢谢!在


Tags: toapp警告标题get属性软件def
1条回答
网友
1楼 · 发布于 2024-05-16 02:11:49

这就是我要做的来识别弹出窗口。实际上,您需要创建一个对话框(dlg),它表示作为弹出窗口父窗口的窗口:

app = pywinauto.application.Application(backend="uia")
app.connect(path='gofer.exe')

# Using regular expression to create a dialog of the gofer.exe app
# I am assuming the title will match "*Gofer*" eg: "Gofer the Application"
dlg = app.window(title_re=".*Gofer.*")

# Now I am going to identify the title of the popup window:
dlg.print_ctrl_ids()

# If you did the last step correctly, the output will look something like:
#Control Identifiers:
#Dialog - 'Gofer The Application'    (L688, T518, R1065, B1006)
#[u'Dialog', u'Gofer Dialog']
#child_window(title="Warning: ", control_type="Window")
   #|
   #| Image - ''    (L717, T589, R749, B622)
   #| [u'', u'0', u'Image1', u'Image0', 'Image', u'1']
   #| child_window(auto_id="13057", control_type="Image")
   #|
   #| Image - ''    (L717, T630, R1035, B632)
   #| ['Image2', u'2']
   #| child_window(auto_id="13095", control_type="Image")
   #|


# Now using the same title and control type for the popup that we identified
# We check to see if it exists as follows:

if dlg.child_window(title="Warning:", control_type="Window").exists():
    print("Bro, you got a pop-up bro...")

else:
    print("No popup Bro...")

相关问题 更多 >