Page 1 of 1

Getting Actual Element Path from Regex Match

Posted: Wed Jul 01, 2015 2:00 pm
by subdavis
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!

Re: Getting Actual Element Path from Regex Match

Posted: Wed Jul 01, 2015 2:28 pm
by odklizec
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.

Re: Getting Actual Element Path from Regex Match

Posted: Wed Jul 01, 2015 3:00 pm
by subdavis
Happily!

I was trying to avoid getting too specific, but this may help.
Capture.PNG
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!

Re: Getting Actual Element Path from Regex Match

Posted: Wed Jul 01, 2015 3:25 pm
by odklizec
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 ;)

Re: Getting Actual Element Path from Regex Match

Posted: Wed Jul 01, 2015 3:41 pm
by subdavis
Sure thing! Here you go:
OwnedTableSnapshot.rxsnp
Thanks again for your help!

Re: Getting Actual Element Path from Regex Match

Posted: Thu Jul 02, 2015 8:47 am
by odklizec
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? ;)

Re: Getting Actual Element Path from Regex Match

Posted: Tue Jul 07, 2015 3:40 pm
by subdavis
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.

Re: Getting Actual Element Path from Regex Match

Posted: Tue Jul 07, 2015 3:44 pm
by odklizec
You are welcome. I'm glad I could help ;)