我正在尝试自动执行Windows gui鼠标单击打印机属性中的复选框。
我通过启动打印管理mmc,右键单击左窗格中“打印服务器”中的“ G23XnQ2E(本地)”并选择属性,然后切换到“安全性选项卡”,终于实现了这一点。管理打印机选项复选框。如果我已经从打印机服务器中选择了“ G23XnQ2E(本地)”,也可以通过直接单击操作菜单并选择属性来实现。
我已经尝试了所有可能的方法,但最终总是遇到许多错误,例如“ raise AttributeError”,“ menu_select”,“ select()”,“ click()”-“缺少”。 / p>
我的代码就像说:
from pywinauto import Application
Application().start(r'mmc printmanagement.msc')
app = Application(backend="uia").connect(path='mmc.exe')
app.PrintManagement.dump_tree()
app.dialog.pane1.pane5.pane6.menu.menu_select("Action -> Properties")
#app.dialog.menu_select("Action -> Properties")
#app.dialog.pane1.pane5.pane6.menu.ActionMentuitem.select()
#app.dialog.pane1.pane5.pane6.menu.ActionMentuitem.click()
如何解决该问题?
答案 0 :(得分:1)
if (href) {
// This is the leaf item case, so the ListItem acts as a link to the href provided.
return (
<ListItem className={classes.itemLeaf} disableGutters {...other}>
<Button
component={props => (
<Link naked activeClassName={classes.active} href={href} {...props} />
)}
className={clsx(classes.buttonLeaf, `depth-${depth}`)}
disableRipple
onClick={onClick}
style={style}
>
{title}
</Button>
</ListItem>
);
}
// This is the case of a parent of nested items.
// Clicking on this toggles the `open` state which opens/closes the Collapse
// which would contain the nested items.
return (
<ListItem className={classes.item} disableGutters {...other}>
<Button
classes={{
root: classes.button,
label: openImmediately ? 'algolia-lvl0' : '',
}}
onClick={this.handleClick}
style={style}
>
{title}
</Button>
<Collapse in={this.state.open} timeout="auto" unmountOnExit>
{children}
</Collapse>
</ListItem>
);
}
适用于“文件->打开”之类的主菜单。它不适用于弹出菜单/上下文菜单。这是我在PC上运行的代码(打印服务器的名称已更改为您的):
menu_select
所有from pywinauto import Application
Application().start(r'mmc printmanagement.msc')
app = Application(backend="uia").connect(path='mmc.exe')
#app.PrintManagement.dump_tree()
print_servers = app.PrintManagement.child_window(title="Print Servers", control_type="TreeItem")
print_servers.select() # it expands the subtree
# call popup menu
print_servers.child_window(title="G23XZNQ2E (local)", control_type="TreeItem").right_click_input()
# alternative way to call popup menu
#print_servers.child_window(title_re=".*\(local\)$", control_type="TreeItem").right_click_input()
# select "Properties..." menu item
app.ContextMenu.child_window(title="Properties...", control_type="MenuItem").select()
#app.PrintManagement.Print_Server_Properties.dump_tree()
app.PrintManagement.Print_Server_Properties.TabControl.select('Security')
app.PrintManagement.Print_Server_Properties.child_window(title="Allow Manage Printers", control_type="CheckBox").toggle()
规范均已从child_window
输出中复制。有些窗口是主窗口的子级,但上下文菜单是顶级窗口。这不是有记录的经验,但是我们正在研究今年计划作为Beta的记录器功能。因此,无需过多考虑层次结构即可轻松生成脚本。