Ranorex

Exception Problem

 
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
CookieMonster



Joined: 14 Aug 2006
Posts: 6

PostPosted: Wed Dec 27, 2006 10:26 pm    Post subject: Exception Problem
Hi I tried handle Exceptions with the Ranorex Pro Version, but I have a few problems.
If I activate Application.ErrorAsException = true; it work fine for the first 3 controls but on the 4th control ranorex throws an Exception, but if deactivate Application.ErrorAsException = true; everthing works fine.
The 4th control will be found without problems.

Best Regards Dan
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Thu Dec 28, 2006 1:56 am    Post subject:
CookieMonster wrote:
but on the 4th control ranorex throws an Exception

Please post your sample code, i would like to know which function throws an exeption.

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
CookieMonster



Joined: 14 Aug 2006
Posts: 6

PostPosted: Thu Dec 28, 2006 7:54 pm    Post subject:
Hi Jenö,


Here is the Method which throws the exception, the follwing Line trows the exception: ctrl = this.frmToAutomate.FindControlName(strElementName);
I think I know where the problem is, during the coding I had never the Exceptions activatet and for that I didn't reconize this problem. I also

Regards Dan
The Method which I used during coding:
Code: click into code to enlarge
 public Ranorex.Element GetElement(String strElementName)
        {
            Element element = null;
            Control ctrl = null;           
            try
            {
                this.frmToAutomate.GetFocus();
                this.frmToAutomate.GetControls();
                if (this.frmToAutomate != null)
                {
                    ctrl = this.frmToAutomate.FindControlName(strElementName);
                    if (ctrl != null)
                    {
                        element = ctrl.Element;                       
                    }
                    else
                    {
                        foreach (Control ctrlElement in this.frmToAutomate.Controls)
                        {
                            if(ctrlElement.Element.Name.Equals(strElementName))
                            {
                                element = ctrlElement.Element;
                                break;
                            }
                        }
                    }                   
                }               
            }
            catch (RanorexException e)
            {
                throw e;
            }
            return element;
        }


I changed the to the following code, but its still not working:

Code: click into code to enlarge
 public Ranorex.Element GetElement(String strElementName)
        {
            Element element = null;
            Control ctrl = null;
            try
            {
                this.frmToAutomate.GetFocus();
                this.frmToAutomate.GetControls();
                if (this.frmToAutomate != null)
                {
                    ctrl = this.frmToAutomate.FindControlName(strElementName);
                    element = ctrl.Element;                   
                }
            }
            catch (RanorexException e)
            {
                throw e;
            }
            finally
            {
                foreach (Control ctrlElement in this.frmToAutomate.Controls)
                {
                    if (ctrlElement.Element.Name.Equals(strElementName))
                    {
                        element = ctrlElement.Element;
                        break;
                    }
                }
            }
           
            return element;
        }


What I'm doing wrong, its not an Bug ??

Best Regards Dan
Back to top
View user's profile Send private message
admin
Site Admin


Joined: 05 Jul 2006
Posts: 351

PostPosted: Thu Dec 28, 2006 9:24 pm    Post subject:
I think the problem is, that you try to find a control with an element name.
If you use the Form.FindControlName function, than you should call the function with the "Control name" property.
Use RanoreySpy to get the control names. In the sample application VS2005Application.exe the control name of the first radio button is "radioButton1" but the element name is "radio1".
You can find the control with Form.FindControlName("radioButton1"), but Form.FindControlName("radio1") throws an exeption.
If you want to find an element in the control, than you should use control.Element.FindChild(role, elementName).

The following code (from the sample application RanorexVS2005Sample3) searches the checked list box control with the control name "checkedListBox1" in the form and then the element "Item2" in the control.

Code: click into code to enlarge
Control checkedListBox = form.FindControlName("checkedListBox1");

Element element = checkedListBox.Element.FindChild(Role.CheckButton,"Item2",null);
if (element != null)
{
  element.Select(Selection.TakeFocus|Selection.TakeSelection);
}


Please try it out and inform me about the results.

Jenö Herget
Ranorex Team
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Ranorex Forum Index -> Bug Reports All times are GMT + 2 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum