pywinauto 判断文件编辑框中的内容
时间: 2023-12-22 10:06:14 浏览: 25
可以使用`pywinauto`的`EditWrapper`类来获取文件编辑框中的内容,示例如下:
```python
from pywinauto.application import Application
# 启动记事本程序
app = Application().start("notepad.exe")
# 连接记事本主窗口
main_dlg = app.top_window()
# 点击“文件”菜单
main_dlg.menu_select("文件(F)->打开(O)...")
# 弹出打开文件对话框
open_dlg = app.top_window()
# 输入文件路径
filename_edit = open_dlg.Edit
filename_edit.set_edit_text("C:\\test.txt")
# 点击“打开”按钮
open_dlg["打开(O)"].click()
# 获取文件编辑框中的内容
main_dlg.Edit.type_keys("^a")
main_dlg.Edit.type_keys("^c")
file_content = app.clipboard.get_text()
print(file_content)
```
首先启动记事本程序,然后通过`menu_select`方法点击“文件”菜单和“打开”菜单项,弹出打开文件对话框。接着使用`set_edit_text`方法输入文件路径,并点击“打开”按钮打开文件。最后,通过`type_keys`方法模拟按下“Ctrl + A”和“Ctrl + C”键获取文件编辑框中的内容,再使用`clipboard.get_text`方法获取剪贴板中的文本内容,即为文件编辑框中的内容。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![xlsx](https://img-home.csdnimg.cn/images/20210720083732.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pptx](https://img-home.csdnimg.cn/images/20210720083543.png)