Page 1 of 1

Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 7:48 am
by lila
Hi ,

I am working on automation of web application. The module that I am currently working on is Admin Module. The Admin module contains the same Admin link named "Settings" multiple times in the page.

Below is the Xpath for one of the "Settings" admin menu link;

?/frame[@name='mainFrame']//frame[@name='nav']//div[#'divText']/table/tbody/tr[3]/?/?/table/ tbody/tr[14]/?/?/a[@innertext='Settings']

The position of "Settings" Admin Menu varies based on the Admin role user is logged in. For one particular admin user the bolded section remains tr[3] and tr[14]. However for another user the element number for tr object changes. Is there anyway by which the Settings Menu could be made unique?

I understand that the only way to be dealt with it is Regex however this is not working here.

any help would be greatly appreciated.

Thanks

Re: Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 8:17 am
by odklizec
Hi Lila,

It would be much much easier if you post a Ranorex snapshot (not screenshot!) of the problematic element. Ideally, post two (or more) snapshots depicting the "admin" links in multiple roles. This would help us to find the best solution of your problem.

Generally speaking, I would definitely suggest to avoid using element indexes. They are unstable and least reliable items in the xpath. Maybe there is another element you can rely on and using relationship operators or relative paths you can uniquely identify the Admin link using this another element? But for this, we need to see the snapshot(s). Thanks.

Re: Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 10:52 am
by odklizec
Hi Lila,

Thanks for the snapshot (sent via PM). OK, it seems that there are multiple "Settings" links in the app. The question is, what exactly you want to do with them (I guess click?) and if only with one of them or all of them?

The one, for which you posted the xpath, belongs to something called EHR. So I would suggest to use the xpath like this, to identify the Settings link based of the EHR header...
/dom[@domain='10.5.39.132']//frame[@name='mainFrame']//frame[@name='nav']//div[#'divText']/table/tbody//td[@innertext=' EHR ']/parent::tr/following-sibling::tr//a[@innertext='Settings']
Hope this helps?

Re: Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 11:16 am
by lila
Hi Pavel,

I used this and it really worked.

But I would like to know how this works and what is the logic behind using this format.

It would be really helpful if you could explain the below mentioned part;

parent::tr/following-sibling::tr

Thanks in Advance for your help.

Regards,
LiLa

Re: Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 12:22 pm
by odklizec
Hi Lila,

Relationship operators are described in Ranorex User Guide:
http://www.ranorex.com/support/user-gui ... html#c5804

Basically, parent::tr returns parent TR element of //td[@innertext=' EHR '] element and then following-sibling::tr returns all sibling TRs from found parent TR element. In your case, it returns two TR elements, but only one of them (first one) contains 'a' tag with innertext 'Settings'. Hope this helps?

Re: Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 1:07 pm
by lila
Hi Pavel,

Thank you so much for the detailed explanation.

This is of great help to me.

With Best Regards,
LiLa

Re: Regular Expression Usage in TR element

Posted: Mon Nov 28, 2016 1:23 pm
by odklizec
You are welcome. I'm glad I could help ;)