Selecting List Item based on multiple child properties

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ChrisSA
Posts: 9
Joined: Tue Jul 17, 2012 2:41 pm

Selecting List Item based on multiple child properties

Post by ChrisSA » Fri Feb 01, 2013 5:49 pm

Hi All,

I'm trying to automate selecting a file (e.g. an install) from a list based on its name (variable) and modified date(variable).

For instance with the following list (Name and Date are different columns):

Name Date
A 2.2 _ES_X_.exe 01/02/2013 13:59
A 2.2 _EN_X_.exe 01/02/2013 11:52
A 2.1 _EN_X_.exe 27/01/2013 05:07

If I want to access the version of file where:
langcode = "EN"
statuscode = "X"
currentdate = "01/02/2013" (will be calculated in UserCode).

The name will eventually follow this structure where the variables represent a language code and status code:
Hopefully this is correct?

Code: Select all

[@text~'ABC.* \_('+$langcode+')\_('+$statuscode+')\.exe']
and the date will be a variable based on the current date:

Code: Select all

[@text~'('+$currentdate+').*']
the text attributes would look something like this after processing:

Code: Select all

/list/listitem/text[@text~'A.*(\_EN\_X\_\.exe']
 /list/listitem/text[@text~'01/02/2013.*']

How would I then use that to select the list item that corresponded to that?


Example from 'Sample Pictures' folder Win7 - set to view 'Details'.
List item Path:

Code: Select all

/form[@title='Sample Pictures']/..LongPath../list/listitem[@accessiblename='Lighthouse.jpg']
Name Path:

Code: Select all

/form[@title='Sample Pictures']/..LongPath../list/listitem[@accessiblename='Lighthouse.jpg']/text[@accessiblename='Name']
Date Path:

Code: Select all

/form[@title='Sample Pictures']/..LongPath../list/listitem[@accessiblename='Lighthouse.jpg']/text[@accessiblename='Date']
Thanks
Chris
Ranorex Version: 4.0.0.20817

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

Re: Selecting List Item based on multiple child properties

Post by Support Team » Mon Feb 04, 2013 5:58 pm

Hello Chris,

You can navigate to the parent element using the string "/../".
For example:
/form[@title='Sample Pictures']/element[@class='ShellTabWindowClass']//list/listitem/text[@accessiblevalue='Chrysanthemum.jpg']/../
Another way is to use the method FindDescendants() and check the value of the descendants from the parent element.
Please find more information in the API Documentation (http://www.ranorex.com/Documentation/Ra ... ant__1.htm).
Please let me know if you need more information.

Regards,
Bernhard

ChrisSA
Posts: 9
Joined: Tue Jul 17, 2012 2:41 pm

Re: Selecting List Item based on multiple child properties

Post by ChrisSA » Tue Feb 05, 2013 12:10 pm

Hi Bernhard,

Thanks for the reply I seem to be having problems with the path that I am using, I have tried adding brackets around the variables as I have seen in some other examples but that doesn't seem to change the result.

Code: Select all

list/listitem[@text~'^Studio.*_'+$LangCode+'_'+$PromotionCode+'_.exe']/text[@accessiblename='Date modified' and @text~''+$CurrentDate+'.*']
when it runs it is not found, returns in the spy as (Using the 'Open in Spy' link from the report):

Code: Select all

/list/listitem[@text~'^Studio.*_'+'EN'+'_'+'X'+'_.exe']/text[@accessiblename='Date modified' and @text~''+'05/02/2013'+'.*']
- Which is not found.

When I use

Code: Select all

/list/listitem[@text~'^Studio.*_EN_X_.exe']/text[@text~'‎05/‎02/‎2013.*' and @accessiblename='Date modified']
the item is found and the action performed.
Ranorex Version: 4.0.0.20817

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

Re: Selecting List Item based on multiple child properties

Post by Support Team » Thu Feb 07, 2013 10:22 am

I just tested the concatenation with variables in RanoreXPaths again and found no problem. So would you do should actually work.

As the first an second path you posted don't work, but the third does, my suspicion is that it's actually a problem of the date format in the path. Have you tried the second path you posted (without variables but with concatenated strings) without the date comparison?
ChrisSA wrote:list/listitem[@text~'^Studio.*_'+'EN'+'_'+'X'+'_.exe']/text[@accessiblename='Date modified']
Regards,
Alex
Ranorex Team

ChrisSA
Posts: 9
Joined: Tue Jul 17, 2012 2:41 pm

Re: Selecting List Item based on multiple child properties

Post by ChrisSA » Thu Feb 07, 2013 11:41 am

Hi Alex,

There is some strange behaviour with this when I initially add this it reports that multiple elements are found (inspecting the 'Date Modified' level) I expect this as without the date there are many with the same name. However when I move back to the parent /listitem level, without making any modifications, after refreshing no elements are found. (see screenshot)
You do not have the required permissions to view the files attached to this post.
Ranorex Version: 4.0.0.20817

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

Re: Selecting List Item based on multiple child properties

Post by Support Team » Thu Feb 07, 2013 4:26 pm

Looks like you found a bug in the Path Editor, it should actually not allow you to edit concatenated attribute values :? When you edit the concatenated value, the Path Editor cannot distinguish if you want to match the concatenated strings or the concatenation string itself. So it changes the attribute comparison to match the whole string, escaping all the ticks inside the former concatenation.

I filed a bug for that issue. Please, meanwhile, do not change concatenated attribute values in the Path Editor! :)
If you edit the RanoreXPath in the text box, without using the Path Editor, the RanoreXPaths you posted earlier should work.

Regards,
Alex
Ranorex Team

ChrisSA
Posts: 9
Joined: Tue Jul 17, 2012 2:41 pm

Re: Selecting List Item based on multiple child properties

Post by ChrisSA » Thu Feb 07, 2013 4:49 pm

Ok thanks I'll give that a go and let you know if I have any further issues with it.

Am I right in thinking you should therefore only add variables to the path using the text box not the path editor also?

Edit: It is quite useful if it was possible to do so in the Path editor as it gives the quick check / highlight and the option to add other variables to the path quite simply.
If it picked up the 'default value' of variables and used them to check if the path was found that would be even more helpful
Ranorex Version: 4.0.0.20817

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

Re: Selecting List Item based on multiple child properties

Post by Support Team » Fri Feb 08, 2013 4:41 pm

ChrisSA wrote:Am I right in thinking you should therefore only add variables to the path using the text box not the path editor also?
Correct. Currently, the path editor is not capable of editing concatenated attribute values correctly, including such with variables.
ChrisSA wrote:If it picked up the 'default value' of variables and used them to check if the path was found that would be even more helpful
This should already work (for non-concatenated attribute values) if you edit a RanoreXPath of a repository item. The RanoreXPath text box editor also provides that feature; when you hit enter, it searches for all items matching the path, replacing variables with their default values.

Regards,
Alex
Ranorex Team