Forum Discussion

rikkilar's avatar
rikkilar
Occasional Contributor
14 years ago

Find child concept

props = Array("tagName", "innerText")

  values = Array("a", "Products")


 

  Set link = page.FindChild(props, values, 10)


In the above code ,

1)how to get the count no of objects find with properties and values mentioned

2)if say i got 4 objects how to access object which is at 2nd position


 

9 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    FindChild only returns the first one matching.



    If you want to return all objects that have that criteria, you should use FindAllChildren.   See http://smartbear.com/support/viewarticle/12741/



    Since, then, FindAllChildren returns an array, after you convert it to the VBArray().toArray as described in that help topic, then you can simply reference Array.length to find out how many objects there are and Array[item] to find the item in the specified position.
  • rikkilar's avatar
    rikkilar
    Occasional Contributor
    In our application on a page we have 1 checkbox ,with findchild method when i used to check the object.



    It throws message,an attempt to perform an action at point (0, 0),which is out of the window bounds



    By changing the other property i am able to check successfully.







    so only by trail and error I am able to find unique property combination.please help out how to handle this problem effectively in first attempt
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    Could you post the code routine that's getting that checkbox?  It sounds like the code for clicking the object is not called correctly.



    If it is a checkbox, have you tried using the ClickChecked method?
  • rikkilar's avatar
    rikkilar
    Occasional Contributor

    I guess i called it correctly,because if i called it wrongly by changing to other property also it should not work





    below is the code for your glance



    props = Array("tagName", "innerText")

      values = Array("a", "Products")


     

      Set checkBox1 = page.FindChild(props, values, 10)



    if checkBox1.exists then

    chekBox1.checked =True

    end if

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    That's kind of strange because the code you posted does not call the "Click" method at all.  That means that the "Click" method that is generating the error is in some different section of code.
  • rikkilar's avatar
    rikkilar
    Occasional Contributor
    you are right,I need to cross check it.





    In general on a page even if we see 1 button through human eye,in real they are other objects with same properties and if we use findchild method it catches first match (and if it is not desired object,It throws message,an attempt to perform an action at point (0, 0),which is out of the window bounds)



    By changing the other property i am able to click successfully.





    so only by trail and error I am able to find unique property combination.please help out to have a block of script  to handle this problem effectively in first attempt .



    Note:I use a frame where i pass object properties and values through datasheet and identify object through script with findchild method
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    so only by trail and error I am able to find unique property combination.please help out to have a block of script  to handle this problem effectively in first attempt .




    Unfortunately, I'm not sure how giving you a block of code will help.  The unique combination of properties that identify an object depend, primarily, on the application that you're testing and how those objects are designed and used.



    Generally speaking, I use idStr with a wildcard on some parts, ObjectType, and innerText.  The combination of those three properties is usually enough.  So, instead of using tagName and innerText, replace with idStr, ObjectType and innerText.


  • rikkilar's avatar
    rikkilar
    Occasional Contributor
    I agree with you that properties depends on AUT.



    The Block of code i am talking about is



    dim select1

    props=Array("idStr")


    values=Array("searchQueryView:content:restrictions:0:operatorItem")


    redim select1(20)


    select1 = Sys.Process("firefox").Page("*").FindallChildren(props, values, 10)


    log.message(ubound(select1))---->(here i am getting 3 objects and desired object is at 3rd positions,in some scenarios it may at second position)


    for i=0 to ubound(select1)


    button(i).click--->(it throwing error for i=0 and stoppping execution as desired object is at 3rd position,so i am looking for your help how to manage script interruption and go to position 3 and identify object),please tell me all possibilties in script  to handle this



    next





    other thing what you suggested to choose idStr,ObjectType,innertext  ( i will try that too)

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    As noted in another thread(http://smartbear.com/forums/forum/post/?mode=singleThread&thread=24472414-4ff0-4c95-82dd-7283a9db47a8), the following code is not recommended for trying to find an object



    for i=0 to ubound(select1)

    button(i).click



    next





    The solution is that you need to change your props array and values array to have more properties and values so that you will find ONLY those objects you want.  Using a single property for finding an object when the page potentially contains many objects that are similar is not a best practice.



    As I mentioned before, those three properties I suggested would be the best choices to populate your two arrays and use those.  That's your answer... don't try to handle button(i).click for objects that don't support click... correct your code so that the for loop is no longer necessary.