This is a migrated thread and some comments may be shown as answers.

How to tell Find.ByType not to throw an exception

3 Answers 52 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kristine
Top achievements
Rank 2
Kristine asked on 20 May 2011, 08:19 AM
Hello Telerik Team,

I need to find an element by using the Find.ByType method. If the element is not found, I want my test to proceed without the Find method throwing an exception. Please see this code:

foreach(Telerik.WebAii.Controls.Xaml.GridViewRow row in Rows)
{
        Telerik.WebAii.Controls.Xaml.RadGridView childgrid = row.Find.ByType<Telerik.WebAii.Controls.Xaml.RadGridView>();
}

I want my test to proceed even if childgrid is null. However, the test is stopping because row.Find.ByType is throwing a timeout exception. Any suggestions?

Regards,
Kristine

3 Answers, 1 is accepted

Sort by
0
Accepted
Stoich
Telerik team
answered on 20 May 2011, 12:30 PM
Hello Kristine,
    generally if you catch the exception like this:
foreach(Telerik.WebAii.Controls.Xaml.GridViewRow row in Rows) {
try{
        Telerik.WebAii.Controls.Xaml.RadGridView childgrid = row.Find.ByType<Telerik.WebAii.Controls.Xaml.RadGridView>();
}
catch (Exception e) { }
}
then your test won't stop executing. However, could you please paste the Timeout error from the log. I'm curious to see what's throwing it because I believe row.Find.ByType<Telerik.WebAii.Controls.Xaml.RadGridView>(); is supposed to simply return NULL if it can't find anything.

Best wishes,
Stoich
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Cody
Telerik team
answered on 20 May 2011, 03:38 PM
Hello Kristine,

Another, probably easier approach, is to change the find strategy right before calling Find like this:

foreach (Telerik.WebAii.Controls.Xaml.GridViewRow row in Rows)
{
    row.Find.Strategy = FindStrategy.WhenNotVisibleReturnNull;
    Telerik.WebAii.Controls.Xaml.RadGridView childgrid = row.Find.ByType<Telerik.WebAii.Controls.Xaml.RadGridView>();
}


Regards,
Cody
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

0
Kristine
Top achievements
Rank 2
answered on 14 Jun 2011, 08:40 AM
Hi Stoich and Cody,

I was able to resolve the problem using Stoich's solution. I'll try Cody's next time. Thanks so much!

Regards,
Kristine
Tags
General Discussions
Asked by
Kristine
Top achievements
Rank 2
Answers by
Stoich
Telerik team
Cody
Telerik team
Kristine
Top achievements
Rank 2
Share this question
or