IList<HtmlTable> allUsers = Find.AllByXPath returns no results, but it should

4 posts, 0 answers
  1. Jurij
    Jurij avatar
    54 posts
    Member since:
    Sep 2013

    Posted 22 Mar Link to this post

    Hello,

    I have a problem finding specific tag, which occurs only once. For example:

    HTML code excerpt:

    <table class="table" id="users-table">
    <tbody>
    <tr class="ng-scope" ng-click="user.id" ng-repeat="user in vm">
    </tr>
    </tbody>
    </table>

     

    Coded step used on HTML code above:

    Manager.ActiveBrowser.RefreshDomTree();        
    IList<HtmlControl> allUsers = Find.AllByXPath<HtmlControl>("table[@id='users-table']/tbody/tr");
    int maxCount = allUsers.Count;
    Log.WriteLine("Found: " + maxCount.ToString() + " elements.");

     

    Problem that I'm facing:

    If I run above coded step it returns maxCount = 0! Instead it should return 1, because one tr tag is available and can be found. If I use online XPATH validators they all return one result (one example of such validator http://codebeautify.org/Xpath-Tester). Let me know why this is happening and how can I solve this? If you have another idea how to solve my problem, please do let me know.

     

    BR, Jurij

  2. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 25 Mar Link to this post

    Hello Jurij,

    You are doing this quite complicated. There is no need to create a collection for the table rows, while you have the rows collection handy and only have to use it once you find the html table. I am providing you a sample code you could use instead yours:

    HtmlTable table = Find.ById<HtmlTable>("users-table");
    var rows = table.Rows;
    Log.WriteLine(rows.Count.ToString());

    Hope this works for you.

    Regards,
    Ivaylo
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
  3. Jurij
    Jurij avatar
    54 posts
    Member since:
    Sep 2013

    Posted 25 Mar in reply to Ivaylo Link to this post

    Hello Ivaylo,

    Perfect!!! this is exactly what I was looking for.

    Thank you!!!

    BR, Jurij

  4. Ivaylo
    Admin
    Ivaylo avatar
    750 posts

    Posted 25 Mar Link to this post

    Hello Jurij,

    You are most welcome.

    Regards,
    Ivaylo
    Telerik
     
    The New Release of Telerik Test Studio Is Here! Download, install,
    and send us your feedback!
Back to Top