Noman Masood
Noman Masood

Reputation: 31

How I can get the current focused element of desktop application

I want to automate my test case for my desktop application(windows application) where I need to get/fetch the currently focused element. Can someone please help me or guide in this regard?

I tried with GetFocus method of pywinauto which just returned the details of Active Window but I need focussed element info

Upvotes: 3

Views: 3089

Answers (1)

Vasily Ryabov
Vasily Ryabov

Reputation: 9981

Currently it's not implemented, but the workaround is possible. For "win32" backend:

import win32gui
from pywinauto.controls.hwndwrapper import HwndWrapper
keyboard_focused = HwndWrapper(win32gui.GetFocus())

For "uia" backend (may not work for WPF app):

import win32gui
from pywinauto.controls.uiawrapper import UIAWrapper
keyboard_focused = UIAWrapper(win32gui.GetFocus())

I've filed issue #760 to implement it later.

Upvotes: 1

Related Questions