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

FindException is not thrown

3 Answers 51 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Dawid
Top achievements
Rank 1
Dawid asked on 09 Feb 2012, 09:59 PM
Hi,
I tried to force my test to throw FindException, so I misspelled one of the IDs, to find element which in fact will be null. And indeed object is null, but FindException is not thrown (but test throws NullReferenceException due to following function, which tries to execute Click() on that element). What could be possible cause of that behavior and how to avoid it?

I'm running tests under .NET Framework 3.5 and nUnit 2.5.1 with WebAii 2011.2.1117.0

3 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 13 Feb 2012, 03:07 PM
Hi Dawid,

I'm sorry you are running into this problem. The Find method returns null if the element is not found instead of throwing an exception and this is by design.

Here's a sample code showing how to overcome this:
HtmlInputSubmit button = Find.ByName<HtmlInputSubmit>("btnK");
if (button == null)
{
    throw new FindException("Element is not found");
}


Note that you need to include the following using statement in order to be able to access the FindException class.
using ArtOfTest.WebAii.Exceptions;


Let me know if you need further assistance on this.

Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Dawid
Top achievements
Rank 1
answered on 13 Feb 2012, 03:21 PM

Thanks for help, but it's not exactly what I meant. I was trying to catch exception in try-catch blocks. I suppose there is no way to manage settings to throw FindException automatically?

Anyway, thanks for your effort.

0
Plamen
Telerik team
answered on 14 Feb 2012, 05:04 PM
Hello Dawid,

Unfortunately, it's not possible to throw a FindException automatically if you are testing HTML app. However, when testing Silverlight applications, you can change the Find Strategy as seen in this article.

Kind regards,
Plamen
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
Tags
General Discussions
Asked by
Dawid
Top achievements
Rank 1
Answers by
Plamen
Telerik team
Dawid
Top achievements
Rank 1
Share this question
or