Hi All,
I am excepting an element which sometimes shows up and someother time doesnt and it depends on testcase. But in our code we have something like below.
Element adjustmentDetailsWindow = Manager.ActiveBrowser.Find.ById("viewDetailsContentWindow");
So problem is when window is present, we get correct results, but if window is not present, then we get an exception saying "Object Reference not set to isntance of object"
I put them in try catch block.But is there any better way to avoid exception as well when window is not present.?
Thanks,
VVP
5 Answers, 1 is accepted
The try/catch block is probably the best option here.
Another option is to use if/else block to check whether the element is null or not and then take some action against it.
Hope this helps.
Regards,
Boyan Boev
Telerik
How to find out whether element is null?
I couldn't find any options to check for null.
Thanks,
VVP
Just simply write:
if
(element==
null
)
{
}
else
{
}
Let me know if this helps.
Regards,
Boyan Boev
Telerik
Hi Boyan Boev,
Exception will be thrown when we try to find the element. So your code wont work.
Element e1 = Manager.ActiveBrowser.Find.ById("duplicateview");
Will throw exception if element with id "duplicateview" is not present.
Thanks,
VVP
Hi,
You can try the following:
Element e1 = Manager.ActiveBrowser.Find.ById(
"duplicateview"
);
Assert.IsNull(e1);
Regards, Ivaylo
Telerik