Page 1 of 1

xPath not identifying/finding windows form correctly

Posted: Tue Feb 09, 2010 1:31 pm
by tommcdonna
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

Re: xPath not identifying/finding windows form correctly

Posted: Tue Feb 09, 2010 6:02 pm
by Support Team
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

Re: xPath not identifying/finding windows form correctly

Posted: Wed Feb 10, 2010 11:16 am
by tommcdonna
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.

Re: xPath not identifying/finding windows form correctly

Posted: Wed Feb 10, 2010 3:18 pm
by Support Team
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

Re: xPath not identifying/finding windows form correctly

Posted: Wed Feb 10, 2010 3:55 pm
by tommcdonna
Find attached (hopefully), my zipped project folder, including the executable TransReport.exe that I'm trying to attach to.

Re: xPath not identifying/finding windows form correctly

Posted: Wed Feb 10, 2010 9:50 pm
by Support Team
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

Re: xPath not identifying/finding windows form correctly

Posted: Thu Feb 11, 2010 1:24 pm
by tommcdonna
Thanks, that makes perfect sense, but I'd never have worked it out myself! :-)