23 Answers, 1 is accepted
You can achieve this via simple find expressions. Read more about them here.
See below for complete sample code against an html table:
HTML:
<!DOCTYPE html>
<
html
>
<
head
>
</
head
>
<
body
>
<
table
border
=
"1"
id
=
"myTable"
>
<
tr
>
<
th
>Header 1</
th
>
<
th
>Header 2</
th
>
</
tr
>
<
tr
>
<
td
>row 1, cell 1</
td
>
<
td
><
a
href
=
"http://www.google.com"
>Google</
a
></
td
>
</
tr
>
<
tr
>
<
td
>row 2, cell 1</
td
>
<
td
>row 2, cell 2</
td
>
</
tr
>
</
table
>
</
body
>
</
html
>
Find expressions (C#):
HtmlTable table =
Manager.ActiveBrowser.Find.ByAttributes<HtmlTable>(
"id=myTable"
);
HtmlAnchor googleLink = table.Find.ByAttributes<HtmlAnchor(
"href=http://www.google.com"
);
googleLink.Click();
This will locate the table with ID="myTable" then it will find and click on a link with href="http://www.google.com".
I recorded a short video as a demonstration.
Hope this helps.
Greetings,
Boyan Boev
the Telerik team
Test Studio Trainings

I dont want to find the element by href, i want to search it using text content or inner text. Coz href is not static in this case, href keeps changing if any changes are made to the element.
I referred this link but couldnt get much help.
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/code-samples/html/table-search-and-paging.aspx
Thanks
Sudarshan
Please see bellow the two examples, that are using text content.
HtmlTable table = Manager.ActiveBrowser.Find.ByAttributes<HtmlTable>(
"id=myTable"
);
HtmlAnchor googleLink = table.Find.ByContent<HtmlAnchor>(
"Google"
);
googleLink.Click();
HtmlTable table = Manager.ActiveBrowser.Find.ByAttributes<HtmlTable>(
"id=myTable"
);
HtmlAnchor googleLink = table.Find.ByExpression<HtmlAnchor>(
"textcontent=Google"
);
googleLink.Click();
Here is another video which demonstrates it.
Regards, Boyan Boev
the Telerik team
Test Studio Trainings

In My Case, i need to click delete or edit button of the dynamic name in the HTML table list using data driven concept. how to do that using coded steps in test studio ? can you provide me with example ?

Once you find the table, you can use these to find the element if the name or any other property is dynamic.
HtmlTable table = manager.Activebrowser.Find.ByAttributes<HtmlTable>("table property"); //Find the table
HtmlControl delete/edit = table.Find.AllByTagIndex<HtmlControl>("tagname", tagindex);
or
var delete/edit = table.Find.AllByTagName<HtmlControl>("tag name of that element");
This will return collection of elements with the tag name u mention and then you can use the index of that element to access that.
Ex: delete/edit[index no].Click();
Thanks
Sudarshan
@Sudarshan - thank you for you input, I've updated your Telerik points.
@Billa - Did this help? Are you still experiencing the issue?
Should you have any additional questions please do not hesitate to ask us.
Boyan Boev
Telerik
Test Studio Trainings

Example:
HtmlTableRow myRow = table.Find.ByExpression<HtmlTableRow>("Innertext=abc01");
HtmlTableRow myRow = table.Find.ByExpression<HtmlTableRow>("Innertext=abc02");
HtmlTableRow myRow = table.Find.ByExpression<HtmlTableRow>("Innertext=abc03");
Please let me know if you want any other details
Regards,
- Suresh
Here is a sample code:
HtmlTableRow myRow = table.Find.ByExpression<HtmlTableRow>(
"Innertext="
+ Data[
"nameOfTheColumn"
].ToString());
Hope this helps. Regards,
Boyan Boev
Telerik
Test Studio Trainings


The first column in html table contains distinct names which is of type hyperlink.
Example
Column1
<a>Name01</a>
<a>Name01</a>
....
<a>Name99</a>
I'm using the below code to search a particular row with the text under column1 & it's not working.
HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=Name01");
Please help me in resolving this issue.

This code will work only if you have one column. As Daniel asked, could you please describe better your testing scenario, so we could help you better. It would also help us if you provide us with a copy of your test and if it is possible grant us access to your application so we can reproduce the issue on our end and give you a solution.
Hope to hear from you soon.
Regards,
Velin Koychev
Telerik
Test Studio Trainings

I have attached a screenshot of sample HTML table which is same as my HTML table.
In the table the data under first column (Column name = CustomerID) is unique and it's hyperlinked.
My Issue:
I want to search a particular CustomerId from first column by it's name & click on it.
Example: I want to search the CustomerID = "KASHM" by name = "KASHM" & click on it.
Please help me in getting this resolved.
Regards,
Suresh
Thank you for the clarifications.
Here is a sample code that executes the same test scenario:
//Find the table on the site.
HtmlTable table = ActiveBrowser.Find.ById<
HtmlTable
>("myTable");
//Get all rows of the table.
IList<
HtmlTableRow
> list = table.Find.AllByTagName<
HtmlTableRow
>("tr");
string name = "KASHM";
//Get the values of the first column.
foreach (HtmlTableRow item in list)
{
//locate the cell from the current row that is in the first column
HtmlTableCell currentCell = item.Cells[0];
//get the link that is inside this cell
HtmlAnchor customerID = currentCell.Find.ByTagIndex<
HtmlAnchor
>("a", 0);
//if the text content of this link is the same as the name, click on the hyperlink
if (name == customerID.TextContent)
{
customerID.Click();
break;
}
}
Let me know if this helps.
Regards,
Velin Koychev
Telerik
Test Studio Trainings

It's working fine with very minor modification.

I have slightly different scenario. I am evaluating Telerik Test Studio for test automation.
I have Html Table something like:
01.
<
div
class
=
"tab-content"
>
02.
<
div
id
=
"divIDname"
class
=
"tab-pane active"
>
03.
04.
<
table
>
05.
<
tr
>
06.
<
th
>Head1</
th
>
07.
<
th
>Head2</
th
>
08.
<
th
>Head3</
th
>
09.
</
tr
>
10.
11.
<
tr
>
12.
<
td
><
a
href
=
"link"
>111111</
a
></
td
>
13.
<
td
><
a
href
=
"link"
>1111</
a
><
br
/>22222</
td
>
14.
<
td
>$434343</
td
>
15.
</
tr
>
16.
</
div
>
17.
</
div
>
I need to click on the first cell of the table data row. I can't use the text because it may change in future. I need to find "111111" (line no.12) element by path. Could you please tell me how can I use XPath or any other Html find expression to find that element in coded step?
Here is how you can locate directly the first table cell (td) in the given div:
HtmlTableCell cell = ActiveBrowser.Find.ByExpression<HtmlTableCell>(
"id=divIDname"
,
"|"
,
"tagIndex=td:0"
);
Here is another approach. It firstly locates the second row of the table and then the first cell:
//Find the div with id "divIDname"
HtmlDiv myDiv = ActiveBrowser.Find.ById<HtmlDiv>(
"divIDname"
);
//Find the table in the div
HtmlTable myTable = myDiv.Find.ByExpression<HtmlTable>(
"tagname=table"
);
//Find the second row
HtmlTableRow row = myTable.Rows[1];
//Find the first cell of the second row
HtmlTableCell cell = row.Cells[0];
Let me know if this helps.
Regards,
Boyan Boev
Telerik
Test Studio Trainings

I used the code below, but it only returned values from the rows inside the <thead></thead> tags.
How do I access the rows inside the <tbody></tbody> tags?
HtmlDiv tDiv = Find.ByAttributes<HtmlDiv>("class=inner");
HtmlTable tTbl = tDiv.Find.ById<HtmlTable>("alerttemplate-list");
IList<HtmlTableRow> list = tTbl.Find.AllByTagName<HtmlTableRow>("tr");
foreach (HtmlTableRow item in list)
{
Log.WriteLine(item.InnerText.ToString());
}
thanks!
Your code seems correct.
Could you please send us the DOM of the table so I can assist you with the code.
Hope to hear from you soon.
Regards,
Boyan Boev
Telerik
Test Studio Trainings

I was able to make my code work!
I just added, ActiveBrowser.RefreshDomTree(); at the top of my code and the row inside the tbody tags were recognized.
thanks!
I am happy to hear that.
If you need further assistance please let us know.
Regards,
Boyan Boev
Telerik
Test Studio Trainings

Hi,
I am trying to automate the similar type of scenario. Application do have a page with HTML table. Each row displays the customer information. First three columns in the table represent Last Name, First Name and Middle Name. Name field in allof these three columns is a hyperlink and on clicking the link user is navigated to another page.
Currently, I am facing issues with the code which performs the task of - Searching the page with the Customer name provided via local data (attached for reference)
When I run the test, below error is displayed even though I have added proper assembly references.
"The type or namespace name 'UI' does not exist in the namespace 'System.Web' (are you missing an assembly reference?)"
Thanks!
This is a duplicate of your other thread.
Please let's continue the discussion there.
Thank you!
Regards,
Boyan Boev
Telerik
Test Studio Trainings