Multiple div's with same ID in my code

2 posts, 0 answers
  1. Ashok
    Ashok avatar
    1 posts
    Member since:
    Jul 2012

    Posted 09 Jul 2012 Link to this post

    Due to some specific reasons, we have to generate a lot of Div tags with same id and class in a table or UL LI . I need help in writing code to find all the occurences of these div elements inside a parent table or UL LI ( parent table ID is known).

    Find.ById pattern i guess simply returns me the first occurrence of the div , How can I get the collection of all such elements, traverse through them and verify the inner text of the div elements.

  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 09 Jul 2012 Link to this post

    Hello Ashok,

    Given the following HTML:

    <table id="table1">
    <tr>
     
    <td>
    <div id="div1">
    <p>Entry 1</p>
    </div>
    </td>
     
    <td>
    <div id="div1">
    <p>Entry 2</p>
    </div>
    </td>
     
    <td>
    <div id="div1">
    <p>Entry 3</p>
    </div>
    </td>
     
    </tr>
    </table>

    Here is how to find each <div> based on the parent <table> and verify the InnerText of each:

    HtmlTable table = Find.ById<HtmlTable>("table1");
    IList<HtmlDiv> list = table.Find.AllByExpression<HtmlDiv>("tagname=div", "id=div1");
     
    foreach (HtmlDiv d in list)
    {
        Log.WriteLine(d.InnerText);
        Assert.IsTrue(d.InnerText.Contains("Entry"), "Assert failed!");
    }


    Greetings,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top