Page 1 of 1

identify an attribute by using a part of its value

Posted: Thu Jan 02, 2014 4:07 pm
by 2ousy
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

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

Posted: Fri Jan 03, 2014 1:51 pm
by MarkusT
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)

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

Posted: Fri Jan 03, 2014 9:27 pm
by 2ousy
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

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

Posted: Tue Jan 07, 2014 10:58 am
by Support Team
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)