Can not find element on form

Class library usage, coding and language questions.
brca
Posts: 2
Joined: Fri Jan 30, 2009 2:06 pm

Can not find element on form

Post by brca » Fri Jan 30, 2009 2:24 pm

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?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Post by Support Team » Fri Jan 30, 2009 4:32 pm

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

brca
Posts: 2
Joined: Fri Jan 30, 2009 2:06 pm

Post by brca » Mon Feb 02, 2009 9:07 am

It's working now.

Thanks a lot.