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
Exception Problem
-
- Certified Professional
- Posts: 74
- Joined: Mon Aug 14, 2006 7:17 pm
- Location: CH
-
- Certified Professional
- Posts: 74
- Joined: Mon Aug 14, 2006 7:17 pm
- Location: CH
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:
I changed the to the following code, but its still not working:
What I'm doing wrong, its not an Bug ??
Best Regards Dan
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: Select all
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;
}
Code: Select all
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;
}
Best Regards Dan
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.
Please try it out and inform me about the results.
Jenö Herget
Ranorex Team
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: Select all
Control checkedListBox = form.FindControlName("checkedListBox1");
Element element = checkedListBox.Element.FindChild(Role.CheckButton,"Item2",null);
if (element != null)
{
element.Select(Selection.TakeFocus|Selection.TakeSelection);
}
Jenö Herget
Ranorex Team