Count objects on a website

Class library usage, coding and language questions.
Hermch
Posts: 40
Joined: Thu May 26, 2011 7:17 am
Location: Germany

Count objects on a website

Post by Hermch » Thu Feb 09, 2012 4:39 pm

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?

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Count objects on a website

Post by Ciege » Thu Feb 09, 2012 4:48 pm

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>();
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Count objects on a website

Post by Aracknid » Thu Feb 09, 2012 11:27 pm

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

Hermch
Posts: 40
Joined: Thu May 26, 2011 7:17 am
Location: Germany

Re: Count objects on a website

Post by Hermch » Fri Feb 10, 2012 8:55 am

Thanks a lot Ciege and Aracknid. Your hints helped me.