need a way to wait till a popup disappears

Ask general questions here.
bhagya
Posts: 11
Joined: Wed Jan 18, 2012 6:48 am

need a way to wait till a popup disappears

Post by bhagya » Tue Apr 24, 2012 12:42 pm

Hi,

i am using Ranorex.dll in my C# script in visual studio. I want to wait till a small dialog disappears. I dont want to use thread.Sleep method. So is there any API in ranorex by which I can wait till the dialog disappears.

Thanks,
Bhagya

User avatar
sdaly
Posts: 238
Joined: Mon May 10, 2010 11:04 am
Location: Dundee, Scotland

Re: need a way to wait till a popup disappears

Post by sdaly » Tue Apr 24, 2012 2:41 pm

This is our framework method for doing so....

To use -

WaitUntilNotExists("rx path to dialog", 60000);


Code: Select all

		/// <summary>
		/// Waits until an rxpath does not exist.  If the timeout passes and the path still exists, an Exception is thrown.  Timeout is specified in ms.
		/// </summary>
		/// <param name="rxPath"></param>
		/// <param name="timeout"></param>
		public static void WaitUntilNotExists(string rxPath, int timeout){
			timeout = timeout / 1000;
			if(timeout < 1 || timeout > 500){throw new Exception("Timeout must be between 1 and 500 seconds.");}
			Ranorex.Unknown element = null;
			int iterations = 0;
			while(Host.Local.TryFindSingle(rxPath, out element)){
				Thread.Sleep(1000);
				iterations ++;
				if(iterations > timeout){
					Report.Failure("Item " + rxPath + " still existed after " + timeout.ToString());
					throw new RanorexException("Item still existed after timeout.");
				}
			}
		}

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: need a way to wait till a popup disappears

Post by Ciege » Tue Apr 24, 2012 3:59 pm

Similarly, here is the method I use... One thing that makes sdaly's method better is that he is using a variable for timeout so that you don't wait too long for the window to disappear.

Code: Select all

bool WindowVisible = MyWindow.Visible;
while (WindowVisible == true)
{
  Thread.Sleep(500);
  WindowVisible = MyWindow.Visible;
}
Last edited by Ciege on Tue Apr 24, 2012 4:11 pm, edited 1 time in total.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

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

Re: need a way to wait till a popup disappears

Post by Support Team » Tue Apr 24, 2012 4:09 pm

The Ranorex Recorder also has a built in "Wait For Not Exists" action. Just select the repository item corresponding to your popup window and a maximum timeout to wait.

See the corresponding Ranorex User Guide section:
http://www.ranorex.com/support/user-gui ... tions.html

Regards,
Alex
Ranorex Team
.
Image

bhagya
Posts: 11
Joined: Wed Jan 18, 2012 6:48 am

Re: need a way to wait till a popup disappears

Post by bhagya » Wed Apr 25, 2012 6:00 am

Thanks for the code snnipet. I tried it and its working.
I also want to know if I am using Ranorex.dll in my visual studio solution, then why all the methods (ex. WaitTillnotExists) are not visible to me. Am I missing any other dll?

User avatar
Ciege
Ranorex Guru
Posts: 1335
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: need a way to wait till a popup disappears

Post by Ciege » Wed Apr 25, 2012 4:18 pm

The "WaitUntilNotExists" method and the snippet I posted are both user generated code snippets not in the Ranorex DLL.
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

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

Re: need a way to wait till a popup disappears

Post by Support Team » Thu Apr 26, 2012 6:24 pm

bhagya wrote:I also want to know if I am using Ranorex.dll in my visual studio solution...
Additionally, make sure that you also add references to all Ranorex.Plugin.*.dll assemblies. Take a look at this section in the Ranorex User Guide for more info.

Regards,
Alex
Ranorex Team
.
Image