identify an attribute by using a part of its value

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
2ousy
Posts: 2
Joined: Thu Jan 02, 2014 2:39 pm

identify an attribute by using a part of its value

Post by 2ousy » Thu Jan 02, 2014 4:07 pm

Hi all,
I am still a beginner with Ranorex, I used to work with Selenium but I think Ranorex well be more useful to me.

But is have a little problem.

I want to select a tag according to a part of its attribute.

For example: an <iframe> tag with attribute name='text1_screenName_text2'

I want to select the iframe by its name by using only (_screenName_) segment ignoring what ever written in (text1) and (text2) segments

how can I do that?!

Thank you

MarkusT

Re: identify an attribute by using a part of its value

Post by MarkusT » Fri Jan 03, 2014 1:51 pm

Hello,

You could use a regular expression within your RanoreXPath using the tilde (~).
Please take a look at the example below that searches for an IFrame that contains 'w3schools' as value for 'src'.

Example page: http://www.w3schools.com/tags/tryit.asp ... tml_iframe
Path: /dom[@caption='Tryit Editor v1.8']//iframe[#'iframeResult']/?/?/iframe[@src~'w3schools']
Ranorex.IFrameTag myTag = Ranorex.Host.Local.FindSingle("/dom[@caption='Tryit Editor v1.8']//iframe[#'iframeResult']/?/?/iframe[@src~'w3schools']");
Report.Info(myTag.Src.ToString());
Please let me know if you need more information.

Regards,
Markus (T)

2ousy
Posts: 2
Joined: Thu Jan 02, 2014 2:39 pm

Re: identify an attribute by using a part of its value

Post by 2ousy » Fri Jan 03, 2014 9:27 pm

Dear MarkusT,

Your solution is working just fine, really really thank you.

Just one more question, how can I force ranorex to ignore location and depend only on the xpath of the element??

Thank you again

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: identify an attribute by using a part of its value

Post by Support Team » Tue Jan 07, 2014 10:58 am

Hello,

You are welcome :-)

You could use a path to ignore elements between the dom object and the IFrame (see below).
It is also possible to ignore the dom object but not recommended since it would take much longer to find the element and the path might not be unique.
// ignore elements between dom object and IFrame
Ranorex.IFrameTag myTag = Ranorex.Host.Local.FindSingle("/dom[@caption='Tryit Editor v1.8']//iframe[@src~'w3schools.com']");		
// search all elements in the Spy hierachy tree - NOT RECOMMENDED
Ranorex.IFrameTag myTag = Ranorex.Host.Local.FindSingle(".//iframe[@src~'w3schools.com']");
Regards,
Markus (T)