Page 1 of 1

Identifying an unexpected GUI control with the focus

Posted: Thu Dec 04, 2014 5:33 pm
by JSH_QA
Normally, we know which control we expect to have the focus at any time, and hence can Find it and get an Element and/or Adapter for it. Being able to direct mouse actions and key strokes to specific controls should ideally mean that we always have control of where the focus is.

However, when the application under test (AUT) is not particularly well behaved, the focus can end up in unexpected places, particularly if the bad behaviour in the AUT is combined with asynchronous behaviour.

I would like, in our test framework, to be able to log information when the focus ends up somewhere unexpected, that will help to diagnose what has happened (and hence which part of the application under test is behaving badly). To help with this, does the Ranorex API provide any way of getting an Element or Adapter for whichever GUI control (I am thinking primarily WPF here) currently has the focus? (i.e. when we don’t have an RxPath or any other idea about where the focus has jumped to).

Many thanks,

John H.

Re: Identifying an unexpected GUI control with the focus

Posted: Thu Dec 04, 2014 5:42 pm
by krstcs
You might try using the following XPath:

Code: Select all

/form[@id='<your form's id>']//element[@hasfocus='true']
Edit to add: You could even create a repo object for this path:

Code: Select all

MainForm ==> /form[@id='myForm']
    FocusElement ==> //element[@hasfocus='true']
Then, just use FocusElement in your test.

Re: Identifying an unexpected GUI control with the focus

Posted: Fri Dec 05, 2014 4:26 pm
by JSH_QA
Brilliant - that will do it.

Many thanks,

John H.