toolbar - 使用 pywinauto 更改工具栏中的文本
问题描述
我有一个来自我试图自动化的 Windows 应用程序的文件选择窗口。
我可以使用更改底部的文件名框
app2.window(title_re='Select a batch file') \
.File_name_Edit.set_text(selected_filename)
我之前在下部框中输入了完整的文件路径和文件名,但是,在 Windows 更新后,它将不再接受文件名框中的斜杠。因此问题。
所以问题是顶部(目录/文件夹名称)框。
手动我可以选择该框,突出显示它然后改写目录。
我找不到使用 pywinauto 的方法。
尝试的方法是:
toolbar2 = app2.window(title_re='Select a batch file') # \
# .child_window(title_re='Address', auto_id='1001')
# .child_window(title_re='Address', control_type="ToolBar", auto_id='1001')
file_path_address = toolbar2['Address band toolbarToolbar'].click_input()
file_path_address.set_text(directory_path)
# ToolbarWrapper(toolbar2).set_text(directory_path)
# ToolbarWrapper(toolbar2).click(button='All locationsSplitButton').set_text(directory_path)
# ToolbarWrapper(toolbar2)['Address:'].set_text(directory_path)
我正在使用 set_text,因为自动化必须在锁定屏幕后运行,type_keys 不适用于锁定屏幕,因为 type_keys 是一种键盘方法,并且当屏幕锁定时 Windows 会阻止键盘输入。
我无权访问正在自动化的程序的内部以更改原始目录路径,并且需要将其更改为从不同位置读取。
任何援助将不胜感激。
解决方案
请参见下面的代码,它在 Win 10 上使用 Notepad++ 运行良好
import time
from pywinauto.application import Application
app = Application().Connect(title=u'Open', class_name='#32770')
window = app.Dialog
toolbarwindow = window.Toolbar3
toolbarwindow.Click()
time.sleep(0.30)
static = window.Edit2
directory_path = "C:\Users\Desktop"
raw_directory_path = r'{}'.format(directory_path)
static.set_edit_text(text = raw_directory_path)
static.type_keys("{ENTER}")
推荐阅读
- c - C中的未知分段错误
- bash - 涉及2个终端的终端脚本
- java - Java OutOfMemoryException 使用 ProcessBuilder
- python - 通过c++20协程制作python生成器
- c++ - BMP180 和 Arduino Mega 导致串行通信冻结
- ios - 发送带有多个附件的电子邮件 (Swift)
- python-3.x - Python 默认行为会吃掉所有输入行,将 EOFError 留给下一个脚本
- linux - 如何知道 .sh 文件内容是在 crontab 中执行的
- python - 有没有一种直接的方法可以使用 Swift 对 Apple Watch 应用程序调用 Python 或 NodeJS API?
- ruby-on-rails-6 - Rails 生产容器“您要查找的页面不存在。”