This is a migrated thread and some comments may be shown as answers.

Working with tablebody

10 Answers 130 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Silvio
Top achievements
Rank 1
Silvio asked on 03 Jan 2013, 02:01 PM
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

10 Answers, 1 is accepted

Sort by
0
Boyan Boev
Telerik team
answered on 07 Jan 2013, 04:39 PM
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
0
Silvio
Top achievements
Rank 1
answered on 10 Jan 2013, 09:03 AM
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
0
Boyan Boev
Telerik team
answered on 10 Jan 2013, 02:57 PM
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
0
Silvio
Top achievements
Rank 1
answered on 11 Jan 2013, 08:32 AM
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.
0
Jared
Top achievements
Rank 1
answered on 29 Sep 2015, 02:50 PM
Is there a solution to a table having multiple tbodys? We really need a tbody class
0
Silvio
Top achievements
Rank 1
answered on 29 Sep 2015, 02:53 PM

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.

0
Jared
Top achievements
Rank 1
answered on 29 Sep 2015, 04:40 PM

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

0
Silvio
Top achievements
Rank 1
answered on 30 Sep 2015, 07:20 AM

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.

0
Jared
Top achievements
Rank 1
answered on 30 Sep 2015, 12:06 PM

Thanks Silvio!

 You are the man :)

0
Boyan Boev
Telerik team
answered on 02 Oct 2015, 07:18 AM
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
 
Tags
General Discussions
Asked by
Silvio
Top achievements
Rank 1
Answers by
Boyan Boev
Telerik team
Silvio
Top achievements
Rank 1
Jared
Top achievements
Rank 1
Share this question
or