Working with tablebody

11 posts, 0 answers
  1. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 03 Jan 2013 Link to this post

    Hi,

    I wonder if there´s any way to effectively work with tablebody-elements. As there is no HtmlTableBody-class, you can just work with it in form of Element, which doesn´t support most important features.
    Most of the time it´s possible to find a workaround, but not in each case.
    I hope you can help me with this.

    Kind regards
    Silvio
  2. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 07 Jan 2013 Link to this post

    Hello Silvio,

    One way to get the tbody element is:

    var tbody = Pages.YourPage.Find.ByExpression("tagname=tbody");

    In order to help you best please elaborate a bit more on your scenario. What exactly do you want to do with tbody tag?

    Thank you for your cooperation.
    All the best,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 10 Jan 2013 Link to this post

    Hi,

    thanks for your reply!

    First of all I don´t work with your base test, so I get the tbody element like this
    manager.ActiveBrowser.Find.ByExpression("tagname=tbody", ...);

    or in most cases like this
    manager.ActiveBrowser.WaitForElement(new HtmlFindExpression("tagname=tbody",
    ...), 10000, false);

    But I had some problems with for instance getting the inner cells. It seems like FindObjectUsed doesn´t do what it should.

    When I run this command
    tbody.FindObjectUsed.AllByTagname<HtmlTableCell>("td");

    I get far more cells than there should be (all cells of current page?).

    I finally solved it by using LINQ
    tbody.Children.Where(c => c.TagName == "td");

    One more feature I´m missing at the Element type, ist the generic Parent<T> property.
     
    But why is there no HtmlTableBody type? 

    Kind regards
    Silvio
  4. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 10 Jan 2013 Link to this post

    Hi Silvio,

    I am happy to hear you have resolved your issue.

    Regarding to your questions.

    1. FindObjectUsed is using the general Find of the browser, therefore it is returning all "td" on the page.

    You can use HtmlTable.BodyRows. It gets the rows contained in the body of the table if the table is using the tbody tag. Now you can get everything from the rows in the tbody.

    I recorded a short video as demonstration.

    3. We haven't implemented the HtmlTableBody type because we/customers very rarely want or need it. It has 4 properties only which are deprecated in HTML 5.

    Let me know if you need additional help.

    Regards,
    Boyan Boev
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  5. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 11 Jan 2013 Link to this post

    Thanks for your help!

    The problem by using table.BodyRows is, that a table can have multiple bodies.

    But in time I think there will be no more problems.

    Kind regards
    Silvio

    Edit:
    Unfortunately the LINQ-solution also seems not to work in each case. At the moment I can only get direct children of tbody => tr, but  I need to assert the text of a span in a td in the tbody. There are many children (unknown count) between parent and children and I don´t know how to assert the text. The only way I can access it is with InnerText property of the tbody element (tbody.InnerText.Contains(text). But this would be a very vague solution.
  6. Jared
    Jared avatar
    6 posts
    Member since:
    Sep 2014

    Posted 29 Sep 2015 Link to this post

    Is there a solution to a table having multiple tbodys? We really need a tbody class
  7. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 29 Sep 2015 in reply to Jared Link to this post

    Hi Jared,

    I've never heard of the requirement for multple tbodies in one table, but you can easily create your own tbody class. Just derive from HtmlContainerControl.

  8. Jared
    Jared avatar
    6 posts
    Member since:
    Sep 2014

    Posted 29 Sep 2015 in reply to Silvio Link to this post

    Hi Silvio

     

    I am in the same predicament you were in I have a table that has multiple tbodys. When I do HtmlTable.BodyRows it only gives me the rows for the first TBody. I am new to c# so I dont know how to implement a new Tbody class. Thanks for your help.

     

    Jared

  9. Silvio
    Silvio avatar
    52 posts
    Member since:
    Dec 2012

    Posted 30 Sep 2015 in reply to Jared Link to this post

    Hi,

     yes, i know that a table CAN have multiple tbodies, but I meant that this shouldn't be a requirement. ;)

    Just derive from HtmlContainerControl, override AssignElement and call ValidateTag ("tbody").

    Then you should also overrride LocatorExpression. Here you could do something like this:

            var findEx = BaseElement == null ? new List<string>() :
            BaseElement.Attributes.Select(a => a.Name + "=" + a.Value).ToList();

            findEx.Insert(0, "tagname=tbody");
            return new HtmlFindExpression(findEx.ToArray());

    I think this should solve your problem. Hope it helps.

  10. Jared
    Jared avatar
    6 posts
    Member since:
    Sep 2014

    Posted 30 Sep 2015 in reply to Silvio Link to this post

    Thanks Silvio!

     You are the man :)

  11. Boyan Boev
    Admin
    Boyan Boev avatar
    1040 posts

    Posted 02 Oct 2015 Link to this post

    Hello,

    @Jared, we are happy that Silvio has helped you in resolving the issue. If you need further assistance please let us know.

    @Silvio, thank you for sharing your knowledge with the community. I have updated your Telerik points for that.

    Thank you!

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