Identifying an unexpected GUI control with the focus

Class library usage, coding and language questions.
JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Identifying an unexpected GUI control with the focus

Post by JSH_QA » Thu Dec 04, 2014 5:33 pm

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.

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: Identifying an unexpected GUI control with the focus

Post by krstcs » Thu Dec 04, 2014 5:42 pm

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.
Shortcuts usually aren't...

JSH_QA
Posts: 56
Joined: Thu Apr 05, 2012 9:03 am

Re: Identifying an unexpected GUI control with the focus

Post by JSH_QA » Fri Dec 05, 2014 4:26 pm

Brilliant - that will do it.

Many thanks,

John H.