Don't throw exception when TimeOut using HtmlElementContainer.Get() method

4 posts, 0 answers
  1. Chhuong
    Chhuong avatar
    7 posts
    Member since:
    May 2009

    Posted 02 Sep 2010 Link to this post

    When I use HtmlElementContainer.Get<HtmlDiv>(...), it will throw exception if it can't find element in the page for a specified period. Is there any setting to return null if the control is not found? I don't want to catch exception every time I find an element.

    Example: this is what I want to do

    HtmlDiv divUserName = HtmlElementContainer.Get<HtmlDiv>(new HtmlFindExpression(...), true, 5000);
    Assert.IsNotNull(divUserName , "Cannot find username control");

  2. Nikolai
    Admin
    Nikolai avatar
    111 posts

    Posted 03 Sep 2010 Link to this post

    Hello Chhuong,

    In general you should not catch the exceptions because this is how all .NET tests are organized. If there is something wrong with your test exception will occur to notify the run-time that something is wrong and the test should fail. After that you examine the stack trace to see what went wrong but if you catch the exception the run-time will continue and ignore the current error so next error will be misleading. In fact all the Assert methods throw exception if their condition is not met so even if you catch the Find exception the Assert will throw one.  

    Currently there is no way to stop the "Get"  method from throwing exception. You can however use Find instead of Get this way if element is not found a Null object can be returned.
     

    Manager.ActiveBrowser.Find.ThrowIfNullOrEmpty = false;
    var divUserName = Manager.ActiveBrowser.Find.ByAttributes<HtmlDiv>("id=MyID");
    Assert.IsNotNull(divUserName , "Cannot find username control");


    All the best,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Chhuong
    Chhuong avatar
    7 posts
    Member since:
    May 2009

    Posted 03 Sep 2010 Link to this post

    Can I specify the timeout with Find like Get() method does (wait for 5000 milliseconds for control to be visible)?

    e.g. HtmlDiv divUserName = HtmlElementContainer.Get<HtmlDiv>(new HtmlFindExpression(...), true, 5000);
  4. Nikolai
    Admin
    Nikolai avatar
    111 posts

    Posted 03 Sep 2010 Link to this post

    Hi Chhuong,

    Unfortunately no you cannot set a TimeOut interval for the Find. You must be sure that the element exists before trying to find it.  

    Regards,
    Nikolai
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top