how to use regular expression in the below object repository

Ask general questions here.
madforoz
Posts: 4
Joined: Tue Sep 28, 2010 1:52 am

how to use regular expression in the below object repository

Post by madforoz » Thu Feb 04, 2016 12:20 pm

Hi,

Could you let me know how to use regular expression in the below object repository?

Object1 XPath:
.//div[#'uniqName_130_0']/div/div[6]/div/div/div/div[10]/input[@type='button']

The highlighted portion in above XPath is dynamic (that is partial value is dynamic). How can we use regular expression here ?

Object2 XPath:
.//td[#'dijit_MenuItem_4_text']

The highlighted portion in above XPath is dynamic (that is partial value is dynamic). How can we use variable here ?

Thanks

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: how to use regular expression in the below object repository

Post by odklizec » Thu Feb 04, 2016 12:36 pm

Hi,

I don't see anything highlighted, but I guess you want to use regex in these unique IDs?...
#'uniqName_130_0'
#'dijit_MenuItem_4_text'

At first, you can't use regex inside unique IDs. You will have to replace unique id identificator '#' with '@id~' attribute.

At second, could you please specify, which parts of ID strings are changing? If only numbers, then you can use something like this...
uniqName_(.*)_(.*)
dijit_MenuItem_(.*)_text
So the whole xpath should look like this:
.//div[@id~'uniqName_(.*)_(.*)']/div/div[6]/div/div/div/div[10]/input[@type='button']
.//td[@id~'dijit_MenuItem_(.*)_text']

Read also this article about automating elements with dynamic IDs:
http://www.ranorex.com/blog/automated-t ... ynamic-ids

I would also suggest to simplify the first path, because there is too many elements and especially element indexes, which are often prone to change.
Try for example this:
.//div[@id~'uniqName_(.*)_(.*)']/div//input[@type='button']
The disadvantage of above xpath could be somewhat slow search.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

madforoz
Posts: 4
Joined: Tue Sep 28, 2010 1:52 am

Re: how to use regular expression in the below object repository

Post by madforoz » Fri Feb 05, 2016 5:44 am

ooops sorry highlighted text below...!

Object1 XPath:
.//div[#'uniqName_130_0']/div/div[6]/div/div/div/div[10]/input[@type='button']

The highlighted portion in above XPath is dynamic (that is partial value is dynamic). How can we use regular expression here ?

Object2 XPath:
.//td[#'dijit_MenuItem_4_text']

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: how to use regular expression in the below object repository

Post by odklizec » Fri Feb 05, 2016 8:18 am

Hi,

Exactly what I expected. Well, as mentioned in my previous post, there is no way to use regexes together with unique ID. Therefore, you will have to change '#' to @id~ syntax. Then you can use regex, as suggested in my previous post, or any regex you like. If you don't care about numbers (their range) used in mentioned IDs, you can simply ignore that part using regex like this:
.//div[@id~'uniqName_'] which means the xpath will be valid for any div element, with id containing 'uniqName_' string.

If your AUT contains too many unique IDs with dynamic parts, you should either to disable search of elements by unique ID in Ranorex settings (in Global Settings >> General tab) or you should create an xpath weight preferring @ID attributes over unique IDs. You can find more details about creating xpath weight in above mentioned blog and Ranorex user guide. Hope this helps? ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration