如何使用pywinauto对子窗口上存在的按钮执行单击操作?

我能够在父窗口上执行按钮单击,但是不确定如何在子窗口的按钮上执行单击操作。

app = Application().connect(path=newPath) 
app.name_of_the_parent_window.draw_outline()
app.name_of_the_parent_window.print_control_identifiers()
app.name_of_the_parent_window.Button6.click()  #this click will open a new window with yes & no buttons.I would like to click on yes button but I am unable to do that

print(app.windows()[0].children(title_re=".*would you like to reset.*",class_name="Button")) #this prints the information about buttons

image of the result of the above print command

我可以看到“是”是一个按钮。但我不知道在按钮yes上执行click()的方法

我尝试了以下命令,但失败并显示错误消息 error mesage image

请让我知道如何在子窗口的按钮上执行点击操作。

wxh19871203 回答:如何使用pywinauto对子窗口上存在的按钮执行单击操作?

它返回ButtonWrapper的列表。因此,您可以选择第一个按钮并为其调用方法.click()。此方法是无提示的(鼠标光标不会移动),因此另一种方法.click_input()执行更逼真的点击。

app = Application().connect(path=newPath) 
app.name_of_the_parent_window.draw_outline()
app.name_of_the_parent_window.print_control_identifiers()
app.name_of_the_parent_window.Button6.click()  #this click will open a new window with yes & no buttons.I would like to click on yes button but I am unable to do that

buttons = app.windows()[0].children(title_re=".*would you like to reset.*",class_name="Button")
print(buttons) #this prints the information about buttons
buttons[0].click() # or buttons[0].click_input()

这是您的代码的快速修复。看起来更不错的方式:

app.name_of_the_parent_window.child_window(title="&Yes",class_name="Button").click()

如果要打印所有可能的child_window规范,请对父窗口规范使用方法.dump_tree()

app.name_of_the_parent_window.dump_tree()

要获取规范的包装对象,请使用方法.wrapper_object()

button_wrp = app.name_of_the_parent_window.child_window(title="&Yes",class_name="Button").wrapper_object()

然后,您可以在IDE中键入button_wrp.,然后查看包装器可用方法的扩展列表。此外,dir(button_wrp)易于使用,它是内置的Python函数,可获取任何Python对象的所有属性(对于检查您不熟悉的对象非常有用)。

本文链接:https://www.f2er.com/2939314.html

大家都在问