How to get informed, the component was loaded

Best practices, code snippets for common functionality, examples, and guidelines.
SomeProgrammer
Posts: 1
Joined: Tue Oct 17, 2017 2:07 pm

How to get informed, the component was loaded

Post by SomeProgrammer » Tue Oct 17, 2017 2:22 pm

I have an application, where I have several components and I have their ID's (strings, with which i can identify them).
I have a button, that creates a complicated component (which ID I also have). So rendering the component takes some time. Now I write code like this:
while (component == null){
..
Thread.Sleep([for some time])
}
And instead, I want to use an event or whatever.
I wonder, whether Ranorex library provides some way to inform, when the component with a specific ID appears on the screen.

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

Re: How to get informed, the component was loaded

Post by Support Team » Tue Oct 17, 2017 6:01 pm

Hi SomeProgrammer,

With Ranorex, you do not need to use a custom Wait-For type method since Ranorex will not perform an action on an element until it exists. Each element in a repository has a specific timeout that sets the maximum time Ranorex will wait for the element to exists. As soon as the item exists, the action is performed. It is recommended to increase this timeout instead of using a custom Wait-For method.

If you still feel a Wait-For method is needed, Ranorex does have a WaitForExist method in its API you can utilize on a repository item's info object (add Info to end of repository object reference).

Code: Select all

repo.MyForm.MyElementInfo.WaitForExists(5000);
I hope this helps!

Cheers,
Ned
.
Image