Forum Discussion

nbenitus's avatar
nbenitus
Contributor
15 years ago

Find and FindAll methods

Hi all,



I am trying to find a group of objects. This is my code:



Dim PropNames, PropValues, Download_Build

  PropNames = Array("innerHTML")

  PropValues = Array("Archive Files")

  Download_Build = NameMapping.FindAll(PropNames, PropValues, 1000, True).href

  Log.Message(Download_Build(0))



At first, I tried the Find method instead of FindAll, which returned me the last object of the group. But I want the first object, so I used the FindAll method. The problem is when I run the FindAll method, I get the following error message:



Object required: 'NameMapping.FindAll(...)'



Unit: "Unit1" Line: 71 Column: 3.




I have read the documentation, but it seems I should be able to use the FindAll method the same way than the Find method.



Any hints would be greatly appreciated.



Benoit







7 Replies

  • Hi Benoit,




    The difference between the FindAll and Find methods is that the FindAll method returns an array of objects and the Find method returns the first found object in the object tree. You get the error message because you are trying to get the value of the href property of the resulting array. You cannot use the href property in such a way. Here's the corrected script:







    Dim PropNames, PropValues, Download_Build


    PropNames = Array("innerHTML")


    PropValues = Array("Archive Files")


    Download_Build = NameMapping.FindAll(PropNames, PropValues, 1000, True)


    Log.Message(Download_Build(0).href)







    BTW, you can reduce the search time when searching for objects by using the FindAll method of a known parent object.
  • Now that you explain it, it makes a lot of sense.



    Thanks a lot David !
  • Hi again,



    I have tried David's solution and it works fine.



    I am trying to optimize the code to search only in IE and not the whole system (it's pretty slow).



    When changing to:



    Download_PCC_Build = iexplore.NameMapping.FindAll(PropNames, PropValues, 1000, True)



    I get a mismatch error. I tried adding "Set" before the line, adding brackets, but without luck.



    Any clues?
  • Hi Benoit,




    I suspect that you need to use the 'NameMapping.iexplore' object instead of 'iexplore.NameMapping':


    Download_PCC_Build =NameMapping.iexplore.FindAll(PropNames, PropValues, 1000, True)





    To know the object name for sure, open the Name Mapping editor (see the "Name Mapping Editor" article for more information), find the 'iexplore' object in the Name Mapping scheme, copy its full name and paste it to the script.
  • Thanks David for the answer.



    NameMapping.iexplore does not seem to work either. (Object doesn't support this property or method: 'NameMapping.iexplore')



    The application I am testing is dynamic, it keeps changing object names, I don't have a choice to use NameMapping.



    Any more clues?



    Thanks in advance :).

  • Hi Benoit,





    Most probably, you need to use the 'NameMapping.Sys.iexplore' object. To know the object name for sure, you need to refer to the Name Mapping editor as I described in my previous post.

    If you still have any problems, please zip your entire project suite folder and send us the archive via our Contact Support form.