Page 1 of 1

Count objects on a website

Posted: Thu Feb 09, 2012 4:39 pm
by Hermch
Hi,

i want to count specific objects on a website, like all input tags, all select tags, all img tags...

i tried it like this:

Code: Select all


Public Sub CountAll()		
			
repo.WebDocument.Login_Page.LoginPage_count.EnsureVisible()
				
Dim objList As IList(Of Ranorex.WebElement) = repo.WebDocument.Login_Page.LoginPage_count.FindDescendants (Of Ranorex.WebElement) ()
			
Dim CountObj As Integer = objList.Count
			
Report.Info("Number of objects: " & CountObj)

Now this code works so far but it counts all the objects on the screen. It also counts BR and TD tags and so on.
I dont want to count these tags.

How can I manage it to count only specific html tags?

Re: Count objects on a website

Posted: Thu Feb 09, 2012 4:48 pm
by Ciege
You need to tell the FindDescendants what type of objects to find.
For example, I use the following to find all Ranorex.Text descendants...

Code: Select all

IList<Ranorex.Text> AllFormText = HDForm.FindDescendants<Ranorex.Text>();

Re: Count objects on a website

Posted: Thu Feb 09, 2012 11:27 pm
by Aracknid
You can look for the specific tags you want, and then add them all up.
e.g.:

Code: Select all

Public Sub CountAll()      
         
repo.WebDocument.Login_Page.LoginPage_count.EnsureVisible()
            
Dim objList As IList(Of Ranorex.WebElement) = repo.WebDocument.Login_Page.LoginPage_count.FindDescendants (Of Ranorex.InputTag) ()
         
Dim CountInputTagObj As Integer = objList.Count
         
objList = repo.WebDocument.Login_Page.LoginPage_count.FindDescendants (Of Ranorex.ImgTag) ()
         
Dim CountImgTagObj As Integer = objList.Count

etc...

Report.Info("Number of objects: " & CountInputTagObj  + CountImgTagObj )

Or you can walk through the objList and look at each element type and if it's the right kind that you want to cound, increment a count.

That's the only 2 ways I can think of, unless there is some sort of magic way to FindDescendants and pre-exclude certain element types.
Aracknid

Re: Count objects on a website

Posted: Fri Feb 10, 2012 8:55 am
by Hermch
Thanks a lot Ciege and Aracknid. Your hints helped me.