GetPath taking very long time to return the path

Class library usage, coding and language questions.
jainaakash
Posts: 48
Joined: Thu Jun 10, 2010 12:06 pm

GetPath taking very long time to return the path

Post by jainaakash » Fri Sep 03, 2010 11:10 am

Hi Team,

I have a typical problem with getpath() taking very long time. Below is the detailed case:

I have a combobox which has more than 2000 listitems. Items are identified as below by Ranorex:
.....combobox/listitems[<index>]/text[@name='<name>']

So, in order to select the required item from the dropdown, I used the following:

Dim cmbBox As Combobox = repo.cmbCedent
Dim strXPath As String = "./listitem/text[@name='"& strName &"']"
Dim xPath As RxPath = new RxPath(strXPath)
Dim lstText As Text = cmbBox.FindSingle(Of Text)(xPath)
lstText.MoveTo
lstText.Click

The above worked fine and it used to scroll down till the Item (as I remember, not sure though) to select it. But now, it does not scroll down till the listitem, instead move to the items position below, and perform a click operation there. Since this click is not on the item and is outside the dropdown list, the item is not selected.

So, I left the above approach and tried a different approach below in which I find the item in the dropdown, get the path of the element, read the index of the listitem, then create a reference to the listitem[@index] and then select & click the listitem[@index].

Dim cmbBox As Combobox = repo.cmbCedent
Dim strXPath As String = "./listitem/text[@name='"& strName &"']"
Dim xPath As RxPath = new RxPath(strXPath)

Dim lstText As Text
Dim found As Boolean = cmbBox.TryFindSingle(Of Text)(xPath, lstText)

' ---- If found Then
Dim strPath As String = lstText.getPath().tostring()
' --------------- THIS TAKES A LOT OF TIME TO RETURN THE VALUE ---------------
' Read the index value for listitem from the above Path and then

Dim str1 As String = "./listitem[" & indexValue & "]
Dim lstRxPath As New RxPath(str1)
Dim lstItm As ListItem
Dim flag As Boolean = cmbBox.TryFindSingle(lstRxPath, lstItm)
lstItm.Select

This works perfectly, the only concern I have here is that the GetPath() it taking toooooo long. On average it about 25 minutes to the return the path of the item. I have tried it multiple times and that was never less than 20 minutes.
Other similar objects return the path quickly. The only difference this object have with others is the number of items in the dropdown. Most of the objects have around 30-40 items. One have around 250 items, for which the getpath() takes about 15-20 seconds to return the path. And this object (combobox) in question has more than 2000 listitems. I still dont see any reason why it should take this long time to return me the path, so that I can perform some calculations and then select the item.

Please help me understand why it (getpath())takes so long here, and if there is a better way of addressing the situation.

Thanks and Regards.
Aakash

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: GetPath taking very long time to return the path

Post by Support Team » Fri Sep 03, 2010 12:41 pm

Hi,
jainaakash wrote:Please help me understand why it (getpath())takes so long here, and if there is a better way of addressing the situation.
It takes time because you are using the find method more than once on your combobox. When you use the Find method, Ranorex every time is searching for all items below the combobox and in your case are about 2000 items nested in the combobox, therefore it takes time. For example if you have only 50 items below your combobox, this will be much faster. To overcome this issue try to use the PathBuildMode Enum of the GetPath() method. Please take a look to following documentation http://www.ranorex.com/Documentation/Ra ... ldMode.htm . To accelerate your code please use the "Simple" member of this Enum.

For example:
repo.YourElement.GetPath(PathBuildMode.Simple)
Another way would be to use the Find method only once and save all children of the combobox to an IList. You can also use a CacheSession to quicken your code. Therefore please take a look at following post http://www.ranorex.com/forum/performanc ... t1155.html

Regards,
Peter
Ranorex Team
.
Image