Getting Actual Element Path from Regex Match

Class library usage, coding and language questions.
subdavis
Posts: 7
Joined: Wed Jul 01, 2015 1:48 pm

Getting Actual Element Path from Regex Match

Post by subdavis » Wed Jul 01, 2015 2:00 pm

Hello folks,

Hopefully you can help me out with the following:

My Scenario: I'm running tests on a page where the element I need is determined by the location of another element, which could be anywhere. I have a 100% success rate at finding the the first "key" using regex. In practice, this involves finding the right table row, then getting other columns in that row. But I'm trying to be abstract.

My Goal: I want to be able to programmatically fetch the ACTUAL xpath of the regex matcher, parse some data out of it, and then programmatically set the xpath of another existing repo item based on my findings.

Is this possible, and how could I go about doing it? Is there a better way? Thanks!

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

Re: Getting Actual Element Path from Regex Match

Post by odklizec » Wed Jul 01, 2015 2:28 pm

Hi,

I'm not quite sure I understand what you want to do? ;) Anyway, it would greatly enhance your chance for answer, if you post a Ranorex snapshot of the element(s) in question. A screenshot with description of related elements would be nice too.
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

subdavis
Posts: 7
Joined: Wed Jul 01, 2015 1:48 pm

Re: Getting Actual Element Path from Regex Match

Post by subdavis » Wed Jul 01, 2015 3:00 pm

Happily!

I was trying to avoid getting too specific, but this may help.
Capture.PNG
Capture.PNG (19.28 KiB) Viewed 1101 times
What I can always find is highlighted in red.

What I need to be able to get is in blue.

As you can see, there are no unique attributes I can get from the two icons at right, other than their position on the table associated with the Instance Name I am trying to find. My goal is to parse the row number out of the Instance cell xpath, then use that to find the icon in the same row.

Example xpath for one of the icons:

Code: Select all

//table[#'BaseSiteMasterMainContent_MainContent_GridViewSharedDatabases_DXMainTable']/tbody/tr[3]/td[10]
EDIT: thanks for the quick response!

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

Re: Getting Actual Element Path from Regex Match

Post by odklizec » Wed Jul 01, 2015 3:25 pm

Hi,

Thanks for the details. It would be really helpful to see also the Ranorex snapshot. I think it should be possible to construct the xpath based of the text in red rectangle, but it would be much easier with snapshot of the table in question ;)
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

subdavis
Posts: 7
Joined: Wed Jul 01, 2015 1:48 pm

Re: Getting Actual Element Path from Regex Match

Post by subdavis » Wed Jul 01, 2015 3:41 pm

Sure thing! Here you go:
OwnedTableSnapshot.rxsnp
(367.93 KiB) Downloaded 59 times
Thanks again for your help!

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

Re: Getting Actual Element Path from Regex Match

Post by odklizec » Thu Jul 02, 2015 8:47 am

Hi,

Sorry for the delay;)

So, here is the path you can use to find the Server Status cell, belonging to the row with selected (known) SQL Instance string:

Code: Select all

/dom[@domain='cloud.stg.sqlsentry.com']//table[#'BaseSiteMasterMainContent_MainContent_GridViewSharedDatabases_DXMainTable']/tbody//td[@innertext='QW63S64-110D']/..//td//img[@alt='SharedServerStatus']/ancestor::td
What you need to to make this path reusable, is to replace the hardcoded innertext value with variable and connect this variable with dataconnector (or fill it somehow from code). So the xpath should look like this:

Code: Select all

/dom[@domain='cloud.stg.sqlsentry.com']//table[#'BaseSiteMasterMainContent_MainContent_GridViewSharedDatabases_DXMainTable']/tbody//td[@innertext=$sqlInstanceValue]/..//td//img[@alt='SharedServerStatus']/ancestor::td
And here is similar for Server Details cell:
/dom[@domain='cloud.stg.sqlsentry.com']//table[#'BaseSiteMasterMainContent_MainContent_GridViewSharedDatabases_DXMainTable']/tbody//td[@innertext=$sqlInstanceValue]/..//td//img[@alt='SharedServerDetails']/ancestor::td

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

subdavis
Posts: 7
Joined: Wed Jul 01, 2015 1:48 pm

Re: Getting Actual Element Path from Regex Match

Post by subdavis » Tue Jul 07, 2015 3:40 pm

Apologies for my delayed response.

This is EXACTLY what I needed. Specifically, the existence of /ancestor::element will be universally helpful for this project.

I _really_ apprecite your help.

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

Re: Getting Actual Element Path from Regex Match

Post by odklizec » Tue Jul 07, 2015 3:44 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