How can I find an inner Element

2 posts, 0 answers
  1. Michael
    Michael avatar
    21 posts
    Member since:
    Apr 2013

    Posted 19 Apr 2013 Link to this post

    In an C# Script the following works:
                Element mainContent;
                mainContent = ActiveBrowser.WaitForElement(Pages.Deuba_Relaunch_FR_Navigation.Expressions.Productoverview_Maincontent_Div, 3000, false);        

    How can i find an Element in mainContent, for Example an Div ?

    It should give me back an HtmlDiv-element like

     HtmlDiv itemCount = Find.ByExpression<HtmlDiv>(new HtmlFindExpression("class=itemCount"));

    Thanks for your help




  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1072 posts

    Posted 22 Apr 2013 Link to this post

    Hi Michael,

    I wrote a simple example against a demo application.

    Here is the HTML:

    <!DOCTYPE html>
    <html>
    <head>
    <title>Div</title>
    </head>
    <body>
        <table id="myTable">
            <tr>
                <td>
                    <div class="itemCount">Here is my div</div>
                </td>
            </tr>
        </table>
    </body>
    </html>
     
    Here I am locating the table and then I am looking for the div inside of the table:

    HtmlTable tab = ActiveBrowser.Find.ById<HtmlTable>("myTable");
    HtmlDiv itemCount = tab.Find.ByAttributes<HtmlDiv>("class=itemCount");
    Log.WriteLine(itemCount.InnerText);

    Here is a video demonstration.

    Hope this helps.

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