Forum Discussion

chrismarriott's avatar
13 years ago

Page.NativeWebObject.Find() - 15 seconds to find an object

Hello,



I'm in the process of writing a script that will help us complete a highly repetitive task.



My problem is that, when using the Page.NativeWebObject.Find() method some objects are taking over 15 seconds to identify the particular item I am specifying in the parameters.



I understand that factors such as page size, location of the desired item in the DOM, hardware of the machine running the test, etc. can affect the speed of finding an object, but I though this was quite excessive.



Do other users find that objects can take this long?



Do other users have other best practices we can employ?



I've attached the particular script for your study.  Things slow down from lines 22 onwards.  The size of source of the page that contain the desried element is around 722KB.



Thanks,

Chris.

1 Reply

  • AlexeyK's avatar
    AlexeyK
    SmartBear Alumni (Retired)

    Christopher,


    As far as I can see, the problem is in the page size and the search approach you are using. You are searching in the entire page, and it takes the Find method some time to go through all the elements. You can try specifying more precise search conditions and narrowing the search range.


    * In your code, you are using the * wildcard, for instance, in the following statement:

    page.NativeWebObject.Find("id", "*_saveNextPrevButtonsTop_questionnaireButtons_btm_right", "a").disabled == false

    This approach takes longer than if using a string without wildcards as the Find method has to check all the variants that match the wildcard string. The value you are searching for seems to be quite unique. Is it necessary to use the wildcard? I'd suggest to get rid of wildcards where they are not necessarily needed.


    * The Find method returns a wrapper test object that TestComplete provides for the page's sought-for element. In many cases, you don't use the wrapper's methods and properties, but use methods and properties of HTML elements. In this case, you can obtain these elements by using a statement like this --


      Page(…).Application.Document.getElementById('id_of_desired_object')


    For example, instead of --

      page.NativeWebObject.Find("id", "*_element_id", "a").disabled == false

    you can use something like this --

      page.Application.Document.getElementById('my_element_id').disabled == false


    When you obtain a page's elements in this way, you don't have access to TestComplete's methods and properties like Click or HoverMouse. However, you don't need them here.


    Statements that use TestComplete's Exists method can be replaced with statements that compare an object with null. For example, instead of  --

       if (page.NativeWebObject.Find("id", "*_txtCommentsTab_ifr", "iframe").Exists)

    you can use something like this --

       if (page.Application.Document.getElementById('id') != null)


    * If you need to simulate user actions on an element, you need to use the Find method. However, in this case, you can try narrowing the search range. Judging by your code, you are searching through the entire page. Is it possible to get an object that is a container for the sought-for elements (e,g. table or div) and then use Find to search for the needed elements in it?