Page 1 of 1

FindSingle & TryfindSingle

Posted: Thu Apr 08, 2010 2:59 pm
by sundarpn
On FindSingle & TryfindSingle method, If one deoes not specifiy the 'Duration', does it mean no waiting?
Or does take into account the global duration?


Also another question,
FindSingle throws and exception while TryFindSingle returns a bool. So I suppose I use tryfindsingle in cases where I want to conditionally test for a widgets presence and branch?

But in cases where I want to defensively check that a widget exists before say clicking on it.... (if not throw an exception) I use FindSingle. Is my interpretation correct?

Re: FindSingle & TryfindSingle

Posted: Thu Apr 08, 2010 5:11 pm
by Support Team
Hi!
sundarpn wrote:On FindSingle & TryfindSingle method, If one deoes not specifiy the 'Duration', does it mean no waiting?
Or does take into account the global duration?
If you define no Duration, the tree is searched only once in descending order. If you pass a duration, e.g. 5 seconds, Ranorex is searching the item for 5 seconds. The method immediately returns when an element is found. The search will be aborted after 5 seconds - even if the element is in the tree, but not found because searching the tree took longer than the timeout.
sundarpn wrote:FindSingle throws and exception while TryFindSingle returns a bool. So I suppose I use tryfindsingle in cases where I want to conditionally test for a widgets presence and branch?
You are right, but for Ranorex repositories, you can also use the RepoItemInfo.Exists() method of the info object corresponding to your repository items:
bool buttonExists = myRepo.MyForm.MyButtonInfo.Exists<Button>();
That way, the timeout values and the path set to the repository item will be used. You can even get the item using the out parameter of the Exists method:
Button myButton;  
bool buttonExists = myRepo.MyForm.MyButtonInfo.Exists<Button>(out myButton);
sundarpn wrote:But in cases where I want to defensively check that a widget exists before say clicking on it.... (if not throw an exception) I use FindSingle. Is my interpretation correct?
Before Ranorex can click on an element, it has to find it first. If you want an exception to be raised when the element is not found, then use FindSingle. There's still the chance that Ranorex could find the element, but the element immediately disappears afterwards and therefore the click won't be performed (no exception will be thrown). To be sure that a click went through, use validation to check the outcome of the click!

Regards,
Peter
Ranorex Support Team

Re: FindSingle & TryfindSingle

Posted: Thu Apr 08, 2010 11:35 pm
by sundarpn
sundarpn wrote:Before Ranorex can click on an element, it has to find it first.
So In the case of a myButton.Click(), before the .click(), ranorex implicitly checks for the buttons to exists & perhaps also visible for it to click. Right?

But later you say that it won't throw an excetion if it does not find it. I find it contradicting.

When i tell ranorex to do "myButton.Click()", and if it cannot find that button (or the button is say not enabled)... shouldn't one expect an exception?

If the above is true, should the scripter always explicitly check that a button exits before calling .Click()?

Re: FindSingle & TryfindSingle

Posted: Fri Apr 09, 2010 8:03 am
by Support Team
sundarpn wrote:So In the case of a myButton.Click(), before the .click(), ranorex implicitly checks for the buttons to exists & perhaps also visible for it to click. Right?
But later you say that it won't throw an excetion if it does not find it. I find it contradicting.
No, Peter did not say that. Please, read Peter's post again carefully, what he wrote is absolutely correct!

With FindSingle Ranorex throws an exception if it can't find the element specified by the RanoreXPath. What Ranorex can't check automatically is whether a button acutally got the click, i.e. if it correctly reacted to the click. You have to do that by checking the result of the click in your application, e.g. by doing a validation and check what the click should have done.
sundarpn wrote:If the above is true, should the scripter always explicitly check that a button exits before calling .Click()?
No, you only need to check for the result of the click, i.e. if your application correctly reacted to the click. It's like in manually testing (but much faster :D): Perform some action, then check the result.

Regards,
Alex
Ranorex Support Team

Re: FindSingle & TryfindSingle

Posted: Fri Apr 09, 2010 3:00 pm
by sundarpn
Thx. Yes, I understand that the logical correctness of a button click has to be tested by validating the whatever happens next on the app.