cancel
Showing results for 
Search instead for 
Did you mean: 

I am getting more object number than actual values when I try to get text fields object counts

DevPerera
Occasional Contributor

I am getting more object number than actual values when I try to get text fields object counts

Hi All,

 

I just want to get number of text fields on particular web page.

Issue is I am getting more number than actual values.

Example if web page contain five text fields, then I am getting count as nine.

 

Here is code written in VB scripts.

 

Sub CountTextFields
PropArray = Array("ObjectType", "Exists", "VisibleOnScreen", "Visible", "Enabled")
ValuesArray = Array("Textbox", "True", "True", "True", "True")
obj = Sys.Browser("iexplore").FindAllChildren(PropArray, ValuesArray,2000)
If UBound(obj) >= 0 Then
Log.Message("Total number of text fields : " & (UBound(obj)))
Else
Log.Warning("No text fields found!")
End If
End Sub

 

................

Thanks

Dev

 

11 REPLIES 11
Colin_McCrae
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

Should the "True" values be in ""?

 

I have a feeling they shouldn't. Try removing the "" from around all the True's in your ValuesArray and see what it returns.

 

Also, have you put a breakpoint on this and inspected the object within the array of results FindAllChildren is generating? What are are the fields in there that you're not expecting?

DevPerera
Occasional Contributor

Re: I am getting more object number than actual values when I try to get text fields object counts

Hi Colin,

 

I tried your suggestion but its not work.

Then I change my code to see all the results its been count as objects.

By looking at the results I can see its duplicate the objects.

Ex; If only one object found then its dispay as two like wise.

 

System results attach here with.

 

Modified code as below.

 

Sub ObjCounts
PropArray = Array("ObjectType", "Exists", "VisibleOnScreen", "Visible", "Enabled")
ValuesArray = Array("Textbox", "True", "True", "True", "True")
obj = Sys.Browser("iexplore").FindAllChildren(PropArray, ValuesArray,2000)
If UBound(obj) > 0 Then
Log.Message("Total number of text fields : " & (UBound(obj)+1))
For i = 0 To UBound(obj)
Log.Message("Object_ID:" & i & "; ObjectType: " & obj(i).ObjectType & ", ObjectIdentifier: " & obj(i).ObjectIdentifier)
Next
Else
Log.Warning("No text fields found!")
End If
End Sub

 

Colin_McCrae
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

OK.

 

So if it's finding duplicates, have you looked at the object model for the application in the object browser? I'm not sure how FindAllChildren can be returning duplicates if you are using VisibleOnScreen (True) as a search value.

 

Are the duplicates present in the object browser?

 

Or it could just be the page. I've had a webpage in the past where Chrome was showing duplicates in the Object Model, but IE didn't.

 

Hard to say without actually seeing the webpage you're looking at ...

DevPerera
Occasional Contributor

Re: I am getting more object number than actual values when I try to get text fields object counts

Hi Colin,

 

Thanks for the repley. I divide the total number by two which return by object counter.

 

Ex; if a page contain object count as one, then function return as two, then I divide that value by two to get correct.

 

 

------------

Thanks

Dev 

Colin_McCrae
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

That still doesn't make sense? Why is it finding double the number you think it should?

 

Have you checked in the Object Browser in the TestComplete IDE to see what it reports?

 

Maybe the devs are doubling them up/overlaying them or something? So maybe there are two of each? I don't know as I can't see the site.

 

But I'd want to know why I was getting two of each. I wouldn't just accept that I have to divide by two and use that as my answer ....

AlexKaras
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

Hi Dev,

 

Have you checked manually if all found objects really exist on the page?

I think that they do exist and that FindAllChildren works correctly. But the real cause of your problem is that for web pages .Visible=True does not guarantee that the object is visible and accessible to the user. The object may not be visible because its parent, or grand-parent, or ... is not visible. Or because object's (or one of its parent's) .height or .width equals to zero. Or because its class is set to be hidden... You should investigate the page and try to find-out the reliable way of how to determine if the given object on the page is visible or not.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Colin_McCrae
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

@ Alex

 

Yeah .... but he's using VisibleOnScreen which (as far as I can tell) is a TestComplete specific property and is accurate. (aka - if the object is off the bottom of the screen and needs scrolled to, it will return False)

 

I agree that I think they probably are present though. Just don't know why. Checking in the object browser will confirm (or not) their presence. Speaking to the devs may or may not find out why they're present ....

AlexKaras
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

Hi Colin,

 

>  VisibleOnScreen which (as far as I can tell) is a TestComplete specific property and is accurate.

I would love it to be always true, but I had a personal experience with some web application when, as I wrote, all reasonable properties (Visible, VisibleOnScreen, Height, Width, ...) indicated that the element must be visible, but in reality it was not because of the reasons I mentioned (some of its parents was not visible (I was lucky enough that it was enough to check parents for no more than three levels up) or the element was not shown because of class SCC setting, etc.).

 

I am not sure that this is a problem of TestComplete, but rather realities of 'modern dynamic and adaptive' web applications.

 

Otherwise I completely agree with your comment.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
Colin_McCrae
Community Hero

Re: I am getting more object number than actual values when I try to get text fields object counts

Interesting.

 

I've had plenty of instances of "Visible" being true when it's not.

 

But VisibleOnScreen has always been accurate for me. I'll keep an eye out for that one!

 

Would still like confirmation of what shows in the object browser in the IDE.

New Here?
Join us and watch the welcome video:
Announcements