Page 1 of 1

Find number of links in a frame

Posted: Tue May 10, 2011 5:12 pm
by Anu
HOw can I find the number of links in a frame?

Newbie to Ranorex

Re: Find number of links in a frame

Posted: Tue May 10, 2011 5:55 pm
by Ciege
You can get an IList of all links:

Code: Select all

IList<Ranorex.ATag> AllATags = MyFrame.FindDescendants<Ranorex.ATag>();
Then you can get a count:

Code: Select all

int count = AllATags.Count; 
Or you can loop through the list:

Code: Select all

foreach (Ranorex.ATag MyTag in AllATags)
{
  //Do Stuff
}

Re: Find number of links in a frame

Posted: Wed May 11, 2011 3:39 pm
by Anu
Hi Ciege,

Thank you for your reply. I think I found another way to achieve my criteria. I could just find my link via findsingle and click on it. I didnt have to use this one for now.

Anu

Re: Find number of links in a frame

Posted: Thu May 12, 2011 10:37 pm
by Anu
Hi Ciege,

Today I have come across a scenario where your suggestion might be useful. But the webpage I am working on is a multi framed app, and if I provide a WebDocument it would give me all the links of the page which is about 327 links. I want the links from a particular frame.
For example this is what I have to get to one submenu link.

/dom[@domain='<IPADDRESS>']/frameset/frameset[@id='contentframeset']/frame[@name='snb']/body/div/table/tbody/tr/td[@id='ltd1']/a[@id='lsnb1']

Thanks for your help
Anu

Re: Find number of links in a frame

Posted: Fri May 13, 2011 11:01 am
by Support Team
Then use instead of the web-document your frame to search for the underlying elements. It the same code for the frame just another RxPath should be used to identify the frame.

Regards,
Peter
Ranorex Team

Re: Find number of links in a frame

Posted: Fri May 13, 2011 3:05 pm
by Anu
WebDocument menupath = "/dom[@domain='<IPADDRESS>']/frameset/frameset[@id='contentframeset']/frame[@name='snb']";
IList<Ranorex.ATag> AllAtags = menupath.FindDescendants<Ranorex.ATag>();

If this is what you mean, than I already tried this and I get an error that the "element does not support the required capability 'webdocument'

Re: Find number of links in a frame

Posted: Mon May 16, 2011 8:49 am
by Support Team
Hi,

Please take a look to following link
http://www.ranorex.com/support/user-gui ... apter.html

This documentation is of 2.x but it is also valid for 3.x. If you read this documentation you will understand what a adapter is. Currently just replace the "WebDocument" Adapter with "FrameTag",then your code should work.

Regards,
Peter
Ranorex Team

Re: Find number of links in a frame

Posted: Mon May 16, 2011 8:37 pm
by Anu
My Code is frame inside frame , inside frame and I did this and it worked.

webDocument frameset = "/dom[@domain='mydomain']";
IList<Ranorex.FrameTag> allframes = mymainframeset.FindDescendants<FrameTag>();
foreach (FramesetTag mymainframeset in allframes
{

//look for another frameset or frame, depending on the type.

}

I have a question tho. Now at some point I am going to define an object say Alltabs which could be a DivTag, or ATag or SpanTag or any other tag. Now how do I declare this object Alltabs in the beginning of the script?

Thanks
Anu

Re: Find number of links in a frame

Posted: Mon May 16, 2011 10:05 pm
by Support Team
Hello Anu,

ATag, DivTag, and so on are all derived from Ranorex.WebElement. You can use that.

Regards,
Roland
Ranorex Support Team

Re: Find number of links in a frame

Posted: Mon May 16, 2011 10:06 pm
by Ciege
First, read the documents, especially the API document...
I have a question tho. Now at some point I am going to define an object say Alltabs which could be a DivTag, or ATag or SpanTag or any other tag. Now how do I declare this object Alltabs in the beginning of the script?
Here are some exampled for declaring variables...

Code: Select all

Ranorex.ATag DOMlink;
Ranorex.InputTag DOMInput;
Ranorex.ImgTag DOMImage;
Ranorex.SelectTag DOMCombo;

Re: Find number of links in a frame

Posted: Tue May 17, 2011 5:10 pm
by Anu
Ciege -I have read it to an extent. But it does not answer my question.

I will try to be clearer. So the way my webapp is designed is very weirdly different. Its all frameset inside frameset inside frame and the objects in the app are not consistently defined. Some objects are recognized by Id, some with name and most of all not all my objects have InnerText. So to get a easier way what I am trying is, find all frames, and then click on the frame with this name, then find all Divs, and find all ATags inside this Div. Thats how I eventually get to my object. in some testcases, I would be grabbing values from spantags, and others i would enter some values to inputtags. I want to be able to reuse the same search function to perform all of this. I am having to repeat the whole set of code for searching different kind of objects.

I want to use the same name "AllTags" in a reusable function, and everytime I call the function I could be looking for ATags, or SpanTags or inputtags depending on what i am going to find . and hence the object definition changes. The way you have mentioned would mean declaring different objects one for each object type.

So our group is going to buy licenses and I have to make sure the tool does everything my app requires. And since the way the app is designed is very complex, I have these questions. Thanks for all your patience.

Anu

Re: Find number of links in a frame

Posted: Tue May 17, 2011 5:31 pm
by Ciege
Well, first off you need to declare the different object variable types so Ranorex know what to look for and how to interact with them. For example, you would interact with an ATag differently than you would a Div.

You can write just a couple of different framework methods that take in a frame object variable then search for a particular set of objects. For example one method would be a find ATags... Have it take a Frame object as its variable and return a list of ATags. Completely re-usable. All you do is pass in a frame object and it returns the ATags in that frame. Do a similar method for each other type of object you want to find. A completely self contained block of code that is reusable throughout this and all of your other projects.

It's all very quite simple once you get your head wrapped around it. And you will eventually build up a large re-usable framework of all your shared methods that can be used again and again. Just put them into a DLL then reference that DLL from all your different test automation projects.

Re: Find number of links in a frame

Posted: Tue May 17, 2011 7:55 pm
by Support Team
Anu wrote:I want to use the same name "AllTags" in a reusable function, and everytime I call the function I could be looking for ATags, or SpanTags or inputtags depending on what i am going to find
As Roland already said, all web elements (ATag, SpanTag, DivTag, ...) derive from WebElement (the API documentation for the class shows the inheritance tree at the very bottom of the page); and WebElement itself and all other adapters (like Button, Text, ComboBox) derive from Adapter. So you can use either WebElement or Adapter as your "AllTags" type.

All adapters and types/classes in the Ranorex Framework are described in the Ranorex API documentation. The important namespace for you is the "Ranorex" namespace:
http://www.ranorex.com/Documentation/Ra ... anorex.htm

Regards,
Alex
Ranorex Team