Page 1 of 1

Can not find element on form

Posted: Fri Jan 30, 2009 2:24 pm
by brca
Hi.

I am evaluating Ranorex 2.0 RC1 for my company.

I have problem with getting text field element. Application is written in Delphi
I always get ElementNotFoundException.

Code: Select all

try:
    path = "/form[@title='Log On'and@processname='Builder'and@class='TLogInForm']"
    loginForm = Ranorex.Host.Local.FindSingle[Ranorex.Form](path, self._timeout)            
    if not loginForm.Active:
        try:
            loginForm.Activate()
        except Ranorex.ActionFailedException:
            return False
except Ranorex.ElementNotFoundException:            
    return False

try:        
    path = "/element[@processname='Builder'and@class='TPanel'and@instance='0']
      /element[@processname='Builder'and@class='TEdit'and@instance='0']
     /text[@accessiblerole='Text']" 
    txtUsername = loginForm.FindSingle[Ranorex.Text](path, self._timeout)
except Ranorex.ElementNotFoundException:
    return False
loginForm is found. I tried to close form, and it works too.

If I try this:

Code: Select all

    path = Ranorex.Core.RxPath.Concat(loginForm.GetPath(), Ranorex.Core.RxPath("/element[@processname='Builder'and@class='TPanel'and@instance='0']
      /element[@processname='Builder'and@class='TEdit'and@instance='0']
      /text[@accessiblerole='Text']"))
    txtUsername = Ranorex.Host.Local.FindSingle[Ranorex.Text](path, self._timeout)
I get the reference to the text field element.

Path is the same as the path in the Ranorex Spy.

Getting just /element[@processname='Builder'and@class='TPanel'and@instance='0'] doesn't work too, but with Ranorex.Host.Local it works.

Am I doing something wrong?

Posted: Fri Jan 30, 2009 4:32 pm
by Support Team
If you use relative RanoreXPaths, you must omit the starting '/' character. '/' at the front of an RxPath means "search from root", i.e. from Host.Local (absolute RanorXPath). So, if you remove that starting '/' when you search for the text inside your form, your code should work.

You can find the documentation for RanoreXPath in the Ranorex User Guide.

Regards,
Alex
Ranorex Support Team

Posted: Mon Feb 02, 2009 9:07 am
by brca
It's working now.

Thanks a lot.