Forum Discussion

DevPerera's avatar
DevPerera
Occasional Contributor
9 years ago

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

  • 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's avatar
      DevPerera
      Occasional Contributor

      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's avatar
        Colin_McCrae
        Community Hero

        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 ...

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    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.

    • Colin_McCrae's avatar
      Colin_McCrae
      Community Hero

      @ 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's avatar
        AlexKaras
        Champion Level 3

        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.