How to Get Active Window

Best practices, code snippets for common functionality, examples, and guidelines.
fgmanfredini
Posts: 5
Joined: Wed Aug 04, 2021 10:26 pm

How to Get Active Window

Post by fgmanfredini » Fri Aug 27, 2021 8:56 pm

Hi, i am using the following code to get the active window,

Code: Select all

Ranorex.Form myActiveForm = Host.Local.FindSingle("/form[@Active='True']"); 
but it does not work, it always return the error:

No element found for path '/form[@active='True']' at step 'form[@active='True']' after 1 attempts.

Am i doing something wrong?

Thank You!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to Get Active Window

Post by odklizec » Tue Aug 31, 2021 8:33 am

Hi,

Unfortunately, it's hard to tell what's wrong without seeing, at very least, a Ranorex snapshot of the problematic app. Could you please share one?

Also, I would suggest to try this xpath...

Code: Select all

Ranorex.Form myActiveForm = Host.Local.FindSingle("//form[@Active='True']"); 
And ideally, start searching for the element from a nearest ancestor/parent element:

Code: Select all

Ranorex.Form myActiveForm = repo.Name.OfParent.FindSingle<Ranorex.Form>(".//form[@Active='True']");
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration