马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我想根据"Import Excel"名字来定位到对应的按钮,然后点击该按钮,但是根据以下代码输出的"控件文本:"都是空的
怎么输出所有控件的名字,或者有什么其他的办法可以定位到这个按钮
import win32gui,time
import win32api,win32con
def get_window_controls_info(window_name):
control_info_list = []
def callback(hwnd, _):
control_info = {}
control_info['hwnd'] = hwnd
control_info['class_name'] = win32gui.GetClassName(hwnd)
control_info['text'] = win32gui.GetWindowText(hwnd)
control_info['rect'] = win32gui.GetWindowRect(hwnd)
control_info_list.append(control_info)
return True
# 查找窗口句柄
hwnd = win32gui.FindWindow(None, window_name)
# 遍历窗口的子控件并获取信息
win32gui.EnumChildWindows(hwnd, callback, None)
return control_info_list
time.sleep(3)
# 调用函数获取窗口上所有控件的信息
window_name = "出货及开票明细报表"
controls_info = get_window_controls_info(window_name)
for control_info in controls_info:
print("控件句柄:", control_info['hwnd'])
print("控件类名:", control_info['class_name'])
print("控件文本:", control_info['text'])
print("控件位置和大小:", control_info['rect'])
print()
输出结果如下:控件句柄: 328926
控件类名: Afx:58990000:0:00010003:00000010:00000000
控件文本:
控件位置和大小: (14, 38, 1426, 69)
控件句柄: 394330
控件类名: ComboBox
控件文本:
控件位置和大小: (54, 43, 196, 65)
控件句柄: 394066
控件类名: Edit
控件文本:
控件位置和大小: (57, 46, 174, 62)
控件句柄: 263398
控件类名: AfxWnd110
控件文本:
控件位置和大小: (14, 38, 14, 38)
控件句柄: 920052
控件类名: AfxWnd110
控件文本:
控件位置和大小: (14, 38, 14, 38)
控件句柄: 1180760
控件类名: AfxWnd110
控件文本:
控件位置和大小: (14, 69, 1426, 78)
|