Checking for the existance of a dialog

Class library usage, coding and language questions.
robinsiebler
Posts: 6
Joined: Tue May 04, 2010 8:04 pm

Checking for the existance of a dialog

Post by robinsiebler » Fri May 07, 2010 8:06 pm

I have a dialog that may or may not appear based on the state of a project. How would I check for the existence of this dialog so that it can be handled?

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

Re: Checking for the existance of a dialog

Post by Ciege » Fri May 07, 2010 8:40 pm

Here is an example of the waitforwindow framework method I wrote for our framework. It will check for a window and if it does not exist throw an error. You can modify it to not throw the error on a failed discovery.

Code: Select all

        public static Ranorex.Form WaitForWindow(string WindowName, int Timeout)
        {
            /************************************************************************
             * Function         : WaitForWindow(string WindowName, int Timeout)
             *
             * Description      : This function will wait for a window with a specific  
             *                  :  Title or ControlName to appear.
             *                         
             * Parameters       : WindowName        - Title or Control Name of the window to wait for
             *                  : Timeout           - Time (in seconds) to wait for the window
             *                                      -  before giving up.
             *                  
             * Return Type      : Ranorex.Form
             * 
             * Return Value     : Ranorex.Form Object for success, null for failure
             * 
             * Revision History
             * Date       : Author                    : Reason/Change
             * ---------- : ------------------------- : ------------------------------
             * 03/05/2009 : Chris Gendreau            : Initial Creation 
             * 05/04/2009 : Chris Gendreau            : Rewritten to use simpler FindSingle method
             * 10/27/2009 : Chris Gendreau            : Added functionality to check for controlname also
            ************************************************************************/
            Ranorex.Form HDForm = null;

            Report.Debug("Waiting for window: " + WindowName);
            try
            {
                HDForm = Host.Local.FindSingle("/form[@title='" + WindowName + "' or @controlname='" + WindowName + "']", Timeout * 1000);
                HDForm.Activate();
                Thread.Sleep(1000);
                return HDForm;
            }
            catch (RanorexException e)
            {
                Report.Debug("Unable to find window: " + WindowName);
                    return null;
            }
        } //End WaitForWindow
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...

robinsiebler
Posts: 6
Joined: Tue May 04, 2010 8:04 pm

Re: Checking for the existance of a dialog

Post by robinsiebler » Fri May 07, 2010 9:16 pm

I'm sorry, I'm new to all of this. Could you give me a Python version of the function and an example of how to use it?

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

Re: Checking for the existance of a dialog

Post by Ciege » Fri May 07, 2010 9:23 pm

Sorry, not using python here nor have I ever used it. I suggest reading the Ranorex documentation for python about the findsingle method which is the crux of this method.
FindSingle does the find of the dialog, then using whatever method python uses catch the exception if the window is not found and handle it accordingly.
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: Checking for the existance of a dialog

Post by Support Team » Mon May 10, 2010 9:58 am

If you use the Ranorex repository, you can use the RepoItemInfo.Exists method to check the existance of an item/dialog, see following blog for more information:
http://www.ranorex.com/blog/handling-di ... up-windows

If you don't use the repository, check out the TryFindSingle method, e.g.:
exists, dialog = Host.Local.TryFindSingle("form[@title='Rechner']")
Report.Info("Dialog exists = " + exists.ToString())
Regards,
Alex
Ranorex Support Team
.
Image

atom
Posts: 357
Joined: Sun Dec 07, 2008 11:14 pm
Location: Dublin, Ireland

Re: Checking for the existance of a dialog

Post by atom » Fri Jun 11, 2010 4:38 pm

If your developers are lazy your error dialogs may have no window title
Sometimes searching for class = #32770 (depending on technology used) will find it

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

Re: Checking for the existance of a dialog

Post by Support Team » Mon Jun 14, 2010 8:42 am

atom wrote:If your developers are lazy your error dialogs may have no window title
Still, Ranorex Spy should give you a unique RanoreXPath able to identify dialogs without title when you track the dialog. Most likely the RxPath will use the class name to identify the dialog, but there may be other attributes as well, as you said "depending on the technology used" :)

Regards,
Alex
Ranorex Support Team
.
Image