HTML Select List Verification

2 posts, 1 answers
  1. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 11 Sep 2013 Link to this post

    Hi

     I have a Html Select List box with Some String for Example
    Test1
    Test2
    Test3

    I need to Verify Test4 is not listed there.

    Could help me in terms of code

    Thanks

  2. Answer
    Boyan Boev
    Admin
    Boyan Boev avatar
    1045 posts

    Posted 16 Sep 2013 Link to this post

    Hi Siva,

    Thank you for contacting us.

    Here is a sample code:

    bool isPresent = true;
    HtmlSelect mySelect = ActiveBrowser.Find.ById<HtmlSelect>("select");
               foreach (HtmlOption item in mySelect.Options)
               {
                   if (item.Text == "Test4'sText")
                   {
                       isPresent = true;
                       break;
                   }
                   else
                   {
                       isPresent = false;
                   }
               }
               Assert.IsTrue(isPresent);

    If there is no item with Test4'sText the test will fail.

    Hope this helps.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top