how to check for the element that is not exist

2 posts, 0 answers
  1. Zin-Mar
    Zin-Mar avatar
    1 posts
    Member since:
    Sep 2010

    Posted 02 Dec 2010 Link to this post

    Hi Telerik team,

    i would like to create a test that depends on 'Remove_Official_Target' link button as shown in my attachment(capture commitment1) .
    If that link button exists, i'll do a, else, i'll do b.
    Currently, i used an if...else statement in my coded step to perform that but it gives me an null exception error when the "'Remove_Official_Target" link doesn't exists.

    The code behind if _ else is below.


            [CodedStep(@"Click 'RemoveLink'")]
            public void CaptureCommitmentTest_CodedStep()
                 if (Pages.FactoryPlanningSystem_2.RemoveLink.IsVisible())
                    // Click 'RemoveLink'
    // Wait for 'TextContent' 'Contains' 'Official Target UnSet' on 'ContentPlaceHolder1LblTargetNonOfficialMessageSpan'
                    HtmlSpan ContentPlaceHolder1LblTargetNonOfficialMessageSpan = Pages.FactoryPlanningSystem_2.ContentPlaceHolder1LblTargetNonOfficialMessageSpan;
                    Wait.For<HtmlSpan>(c => c.AssertContent().TextContent(ArtOfTest.Common.StringCompareType.Contains, "Official Target UnSet"), ContentPlaceHolder1LblTargetNonOfficialMessageSpan, 10000);
                           // Add your test methods here...

    I try to if (Pages.FactoryPlanningSystem_2.RemoveLink.IsVisible())  with if (Pages.FactoryPlanningSystem_2.RemoveLink != null) .
    It gives the same error.

    Any advice on this?

  2. Keaegan
    Keaegan avatar
    126 posts

    Posted 06 Dec 2010 Link to this post

    Hi Zin-Mar,

    Did you get our reply to your support inquiry on this ticket? Please let us know if you are still having the same issues with this facet.

    All the best,
    the Telerik team

    Interested in Agile Testing? Check out Telerik TV for a recording of Automated Testing in the Agile Environment
Back to Top