Page 1 of 1

Which is faster

Posted: Thu Nov 12, 2009 4:20 pm
by Marianne Jacobsen
Assuming an absolute RanoreXpath.

Which is faster - or is there any difference at all?

Element element = absolutXpathhere;
or
form.FindSingle(absolutXpathhere)

Re: Which is faster

Posted: Thu Nov 12, 2009 4:35 pm
by Support Team
If it is an absolute RanoreXPath, i.e. a path starting with "/", both statements are equal in speed.

The only difference is that the first statement (the implict assignment from path to element) uses the Adapter.DefaultSearchTimeout whereas the second statement does not use a timeout. The equivalent code for both statements would be:
Element element = absolutXpathhere;
// equals
Element element = Host.Local.FindSingle(absolutXpathhere, Adapter.DefaultSearchTimeout);
Element element = form.FindSingle(absolutXpathhere);
// equals (only for absolute paths!)
Element element = Host.Local.FindSingle(absolutXpathhere);
So, the second statement will search for the RanoreXPath only once, whereas the first statement searches several times until the timeout is reached. That means, if the UI element is already there when the search is started, both statements are equivalent. However, if the element is not there yet and spawns inside the timeout, the first statement will find the element, but the second one will fail, since it searches only once.

Regards,
Alex
Ranorex Support Team

Re: Which is faster

Posted: Thu Nov 12, 2009 4:39 pm
by Marianne Jacobsen
Super - just the reply I was hoping for.

Thanks for the quick respond :D

Re: Which is faster

Posted: Thu Nov 19, 2009 8:10 pm
by atom
This is news to me... why does FindSingle not apply the timeout?
I was under the impression all Find methods did, or should!

Does TryFindSingle apply the timeout?

Re: Which is faster

Posted: Fri Nov 20, 2009 1:45 pm
by Support Team
atom wrote:Does TryFindSingle apply the timeout?
Only if you specify a timeout.

FindSingle without timeout parameter evaluates the specified path exactly once. No timeout is applied.
FindSingle with timeout parameter evaluates the specified path as long as the timeout is reached or an element is found.
TryFindSingle and Find methods work exactly the same: no timeout is applied if you do not specify a timeout.

The Adapter.DefaultSearchTimeout is only used when you use direct assigning of a path to an adapter/element variable, i.e. when you do not use Find/FindSingle/TryFindSingle:
Text text = "/form[@title='My Form']/text";
If you want to use the Adapter.DefaultSearchTimeout for your Find/FindSingle/TryFindSingle methods, just pass it as a parameter. The following statement is equivalent to the code above:
Text text = Host.Local.FindSingle("/form[@title='My Form']/text", Adapter.DefaultSearchTimeout);
Regards,
Alex
Ranorex Support Team

How to make FindSingle (or similar) faster?

Posted: Sat May 01, 2010 12:25 am
by spot
Hello,

I've got an container for some tabpages and textboxes on each of these tabpages (in container with different rxpath depth to the tabpage itself). To make it more general I take only one rxpath to the container of all tabpages and then I search for the specific text boxes.
// for example:
// 0. equal
string rxpathToTabContainer = "/form[@controlname='SpForm']/element[@controltypename='MdiClient']/form/container/element/container/container/container/element[@controlname='DetailWorkSpaceDeView']";
// 1. shorter rxpath (only for better understanding)
string rxpathToDevExpressTextBoxOnTabPage1 = rxpathToTabContainer + "/container/container/container/element[@controlname='extId2TextEdit']";
// 2. longer rxpath (only for better understanding)
string rxpathToDevExpressTextBoxOnTabPage2 = rxpathToTabContainer + "/container/container/container/container[@controlname='geocodingContainer1']/container/container[@controlname='gcAddress']/container[@controlname='addressControl']/container/element[@controlname='postCodeTextBox']";

// used code:
Ranorex.Control detailWorkSpace = rxpathToTabContainer ;
string detailItemName1 = "extId2TextEdit";
Ranorex.Control detailItem1 = detailWorkSpace.FindSingle(".//element[@controlname='" + detailItemName1 + ']");
string detailItemName2 = "postCodeTextBox";
Ranorex.Control detailItem2 = detailWorkSpace.FindSingle(".//element[@controlname='" + detailItemName2 + ']");
The time to get detailItem1 (about 1 second) is much more faster then for detailItem2 (about 13 seconds).
So my question: Is there any way to get a fast - or much more faster - FindSingle (or something else)?

Re: Which is faster

Posted: Mon May 03, 2010 1:55 pm
by Support Team
Hi!
spot wrote:So my question: Is there any way to get a fast - or much more faster - FindSingle (or something else)?
The reason why "detailItemName1" is faster than "detailItemName2" is following. FindSingle with timeout parameter evaluates the specified path as long as the timeout is reached or an element is found. So I think the "detailItemName1" element is on a higher level than "detailItemName2". When you use ".//element" in your code, this means you search the whole tree descending as long you find the item or the timeout is reached.The faster way would be, when you specify the path in more detail for the second item. Or just use the repository items. Repository items in most cases show you the best way to identify an element.

Regards,
Peter
Ranorex Support Team

Re: Which is faster

Posted: Tue May 04, 2010 1:00 pm
by spot
Okay, when there is no faster way - or faster method - then I must try to work with a path in more detail.

Thank you.