Regular Expression Usage in TR element

Ask general questions here.
lila
Posts: 21
Joined: Wed Jun 18, 2014 10:17 am

Regular Expression Usage in TR element

Post by lila » Mon Nov 28, 2016 7:48 am

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

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

Re: Regular Expression Usage in TR element

Post by odklizec » Mon Nov 28, 2016 8:17 am

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.
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

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

Re: Regular Expression Usage in TR element

Post by odklizec » Mon Nov 28, 2016 10:52 am

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?
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

lila
Posts: 21
Joined: Wed Jun 18, 2014 10:17 am

Re: Regular Expression Usage in TR element

Post by lila » Mon Nov 28, 2016 11:16 am

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

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

Re: Regular Expression Usage in TR element

Post by odklizec » Mon Nov 28, 2016 12:22 pm

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?
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

lila
Posts: 21
Joined: Wed Jun 18, 2014 10:17 am

Re: Regular Expression Usage in TR element

Post by lila » Mon Nov 28, 2016 1:07 pm

Hi Pavel,

Thank you so much for the detailed explanation.

This is of great help to me.

With Best Regards,
LiLa

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

Re: Regular Expression Usage in TR element

Post by odklizec » Mon Nov 28, 2016 1:23 pm

You are welcome. I'm glad I could help ;)
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