uiautomation.WindowControl
时间: 2023-09-22 21:08:36 浏览: 55
`UIAutomation.WindowControl` 是一个 Windows UI 自动化库的类,它允许开发人员通过编程的方式与 Windows 应用程序进行交互和控制。这个类提供了一系列方法和属性,可以帮助开发人员访问和操作应用程序的 UI 元素,例如窗口、按钮、文本框等等。通过使用 `UIAutomation.WindowControl`,开发人员可以自动化执行一些任务,例如测试应用程序的 UI、生成 UI 自动化脚本等等。
相关问题
from uiautomation import WindowControl,MenuControl import pandas as pd import numpy as np wx=WindowControl( Name='微信', #searchDepth=1 ) print(wx) wx.SwitchToThisWindow() hw=wx.ListControl(Name='会话') print('寻找会话控制绑定',hw) df = pd.read_csv('E:/pycharm/回复数据.csv', encoding='gb18030') while True: we=hw.TextControl(searchDepth=4) while not we.Exists(8): pass print('查找未读消息',we) if we.Name: we.Click(simulateMove=False) last_msg=wx.ListControl(Name='消息').GetChildren()[-1].Name print('读取最后一条消息',last_msg) msg=df.apply(lambda x:x['回复内容']if x['关键词']in last_msg else None,axis=1) msg.dropna(axis=0,how='any',inplace=True) ar=np.array(msg).tolist() if ar: wx.SendKeys(ar[0].replace('{br}','{Shift}{Enter}'),waitTime=0) wx.SendKeys('{Enter}',waitTime=0) wx.TextControl(SubName=ar[0][:5]).RightClick() else: wx.SendKeys('我没明白你的意思',waitTime=0) wx.SendKeys('{Enter}',waitTime=0) wx.TextControl(SubName=last_msg[:5]).RightClick() 这行代码出错了 Traceback (most recent call last): File "E:\pycharm\002.py", line 43, in <module> wx.TextControl(SubName=last_msg[:5]).RightClick() File "E:\Python\lib\site-packages\uiautomation\uiautomation.py", line 6580, in RightClick point = self.MoveCursorToInnerPos(x, y, ratioX, ratioY, simulateMove) File "E:\Python\lib\site-packages\uiautomation\uiautomation.py", line 6507, in MoveCursorToInnerPos rect = self.BoundingRectangle File "E:\Python\lib\site-packages\uiautomation\uiautomation.py", line 5907, in BoundingRectangle rect = self.Element.CurrentBoundingRectangle File "E:\Python\lib\site-packages\uiautomation\uiautomation.py", line 6224, in Element self.Refind(maxSearchSeconds=TIME_OUT_SECOND, searchIntervalSeconds=self.searchInterval) File "E:\Python\lib\site-packages\uiautomation\uiautomation.py", line 6475, in Refind raise LookupError('Find Control Timeout({}s): {}'.format(maxSearchSeconds, self.GetSearchPropertiesStr())) LookupError: Find Control Timeout(10s): {SubName: '你你你', ControlType: TextControl} 进程已结束,退出代码1 是什么问题,怎么解决
这个错误提示表明在使用uiautomation库的时候,查找窗口控件超时了。可能是由于该控件没有及时加载或者在当前窗口中不存在。
你可以尝试增加等待时间,或者使用其他查找控件的方法。例如,可以使用FindAll方法查找所有符合条件的控件,并从中选择需要的控件。另外,也可以使用TryGetClickablePoint方法来判断控件是否可点击。
以下是使用FindAll方法查找控件的示例代码:
```python
import uiautomation as auto
# 查找所有SubName为'你你你'的TextControl控件
controls = auto.FindAll('ControlType.TextControl', SubName='你你你')
# 从中选择第一个控件并右键点击
if controls:
control = controls[0]
control.RightClick()
else:
print('未找到控件')
```
如果还是无法解决问题,可能需要检查窗口是否已打开或者控件是否已加载完成。
Python调用uiautomation
如何在Python中调用uiautomation?
1. 安装uiautomation模块。可以使用pip命令进行安装:
```
pip install uiautomation
```
2. 导入uiautomation模块。在Python代码中导入uiautomation模块:
```python
import uiautomation as automation
```
3. 使用uiautomation模块进行UI自动化操作。可以使用uiautomation模块的API来获取UI元素并执行操作,例如:
```python
# 打印桌面上所有窗口的标题
for window in automation.GetRootControl().GetChildren():
print(window.Name)
# 在Windows 10的开始菜单中搜索"word"并打开"Word 2016"应用
start_menu = automation.WindowControl(Name='Start menu')
search_box = start_menu.EditControl(AutomationId='CortanaEditBox')
search_box.Click().SendKeys('word').SendKeys('{ENTER}')
word_app = automation.WindowControl(Name='Word 2016')
word_app.Click()
```
更多uiautomation模块的API可以参考官方文档:https://github.com/yinkaisheng/Python-UIAutomation-for-Windows/blob/master/doc/uiautomation.md
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](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)