xPath not identifying/finding windows form correctly

Ranorex Spy, Recorder, and Studio.
tommcdonna
Posts: 4
Joined: Tue Feb 09, 2010 1:12 pm

xPath not identifying/finding windows form correctly

Post by tommcdonna » Tue Feb 09, 2010 1:31 pm

I keep getting the following error when I attempt to run my script:

Ranorex.ElementNotFoundException: No element found for path '/form[@controlname='frmMain']' within 10s.

The calling code is below:

System.Diagnostics.Process.Start("C:\\Temp\\TransReport.exe");
Delay.Milliseconds(10000);
Ranorex.Form TransReport = "/form[@controlname='frmMain']";

When I use Ranorex Spy, the form I want to find is successfully highlighted using the xPath as above.

This is happening with version 2.2.1.7599

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: xPath not identifying/finding windows form correctly

Post by Support Team » Tue Feb 09, 2010 6:02 pm

Maybe the default search timeout is too small. Try using the FindSingle method instead with a high timeout value:
Ranorex.Form TransReport = Host.Local.FindSingle("/form[@controlname='frmMain']", 60000);
Another problem with Windows Forms application could be 32/64 bit interoperability - do you work on a 64 bit operating system? If yes, please follow the guidelines in the Ranorex User Guide: http://www.ranorex.com/support/user-gui ... forms.html

Also consider updating to the latest Ranorex release V2.2.2!

Regards,
Alex
Ranorex Support Team
.
Image

tommcdonna
Posts: 4
Joined: Tue Feb 09, 2010 1:12 pm

Re: xPath not identifying/finding windows form correctly

Post by tommcdonna » Wed Feb 10, 2010 11:16 am

I first upgraded to the latest 2.2.2 release.

Then I retried the original script, problem still occurs.

I tried with the FindSingle method, same problem occurs.

Iam using 32bit XP Pro, so 64bit issues are not the cause.

The form (and a few child buttons and text boxes) are all in the object repository, when I select 'highlight repository item' the form is successfully identified using exactly the same xPath as used in the script.

The 'Element Browser' and 'Spy' both confirm the xPath is correct too.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: xPath not identifying/finding windows form correctly

Post by Support Team » Wed Feb 10, 2010 3:18 pm

If Ranorex Spy can identify the element/form correctly, you can definitely do that in code, too. There must be some difference between the path in Spy and in code or some other problem in the code preventing the identification.
  • Have you tried your code in a brand new Ranorex project? I.e. create a new C# Automation Project in Ranorex Studio and paste your code there. Does that work?
  • Do you have the STAThread attribute applied to the Main method of your application and does every thread executing Ranorex code have an STA?
It would be nice if you could post your code and a snapshot of your application to the forum!

Regards,
Alex
Ranorex Support Team
.
Image

tommcdonna
Posts: 4
Joined: Tue Feb 09, 2010 1:12 pm

Re: xPath not identifying/finding windows form correctly

Post by tommcdonna » Wed Feb 10, 2010 3:55 pm

Find attached (hopefully), my zipped project folder, including the executable TransReport.exe that I'm trying to attach to.
Last edited by tommcdonna on Thu Feb 11, 2010 1:25 pm, edited 1 time in total.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: xPath not identifying/finding windows form correctly

Post by Support Team » Wed Feb 10, 2010 9:50 pm

The problem in that particular case is that your test executable and the application under test (AUT) have the same DLL/EXE name, even the same assembly identity. In order to automate .NET applications, Ranorex loads the assemblies (DLLs/EXE) of that application. As the assembly identities are exactly the same in your example, Ranorex and the .NET Framework think that the AUT assembly is already loaded (although actually only the test assembly is loaded) and can't recognize the .NET form any more.

There are two solutions: Rename your test executable (Project Settings -> Assembly Name) or define a strong name for the AUT or the test executable (Project Settings -> Signing). Both solutions create unique names for both the AUT and the test executable.

Regards,
Alex
Ranorex Support Team
.
Image

tommcdonna
Posts: 4
Joined: Tue Feb 09, 2010 1:12 pm

Re: xPath not identifying/finding windows form correctly

Post by tommcdonna » Thu Feb 11, 2010 1:24 pm

Thanks, that makes perfect sense, but I'd never have worked it out myself! :-)