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
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
Test Studio Trainings
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
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.
Boyan Boev
the Telerik team
Test Studio Trainings
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.
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.
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
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.
Thanks Silvio!
You are the man :)
@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
Test Studio Trainings