Forum Discussion

aazimurj's avatar
aazimurj
Occasional Contributor
9 years ago

Performance comparison between FindChildByXpath and EvaluateXpath

Hi,

   Can someone please help me understand if there is any difference between FindChildByXpath and EvaluateXpath functions with respect to performance?

 

My understanding of these functions from documentation is that EvaluateXpath would search all web elements and would store all matching elements into an array. On the other hand FindChildByXpath would try to search all web elements but if it encounters any object matching the Xpath, it would stop search and return the object.

 

Going ahead with this understanding I expect FindChildByXpath to work faster than EvaluateXpath if there are 3050 input type web elements in a page.

 

 

So i wrote below code to test for it

 

sub mytest
 XPath = "//input[@id='test']"
 set PageObj = Sys.Browser("iexplore").Page("*")
 set ParObj = PageObj.FindChildByXpath(".//*[@id='test2']")
 startTime = Timer()
 set myEle = ParObj.FindChildByXPath(Xpath)
 endTime = Timer()
 if not myEle is Nothing then
  log.Message "Time to find object using FindChildByXpath: " + FormatNumber(endTime - startTime, 2)
 end if

 startTime = Timer()
 myEle = ParObj.EvaluateXpath(Xpath)
 endTime = Timer()
 if not isNull(myEle)then
  log.Message "Time to find object using EvaluateXpath: " + FormatNumber(endTime - startTime, 2)
 end if
end sub

 

OUTPUT:

Iteration:1
Time to find object using FindChildByXpath: 12.01
Time to find object using EvaluateXpath: 12.17

 

Iteration:2
Time to find object using FindChildByXpath: 12.24
Time to find object using EvaluateXpath: 11.88

 

Iteration:3
Time to find object using FindChildByXpath: 11.95
Time to find object using EvaluateXpath: 12.21

 

Iteration:4
Time to find object using FindChildByXpath: 12.14
Time to find object using EvaluateXpath: 11.97

 

I am confused with the output because alternatively it seems evaluateXpath works better than findChildByXpath. Is it a bug?

 

Is it the case that FindChildByXpath still searches through the whole web page elements even if it encountered the matched object and only after finishing search it returns the object?

 

Problem is I have set of testscripts which currently uses EvaluateXpath and TC takes roughly 10-14 secs to find and perform single operation. As a result i have to wait for almost an hour for test execution to finish. If i do the same testcase manually, it would roughly take 15 - 20 minutes to finish.

 

Hence I was thinking to change EvaluteXpath to FindChildByXpath as most of the controls have unique id.

I have already implemented other performance improvement tips suggested by TC

1 Reply

  • TanyaYatskovska's avatar
    TanyaYatskovska
    SmartBear Alumni (Retired)

    Hi Aazimurj,

     

    As far as I know, the only difference between the methods is that FindChildByXPath starts searching for an object among child objects, while EvaluateXPath starts searching within the object you call the method. So, theoretically, EvaluateXPath can work a bit longer. However, I don’t think that the time difference should very high.

     

    BTW, what TestComplete version are you using? There was a known issue in TestComplete 11.10 – searching for objects via XPath could take much time. This issues was fixed in TestComplete 11.11.