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

Click on Table Row with a Variable Name

7 Answers 245 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Nate
Top achievements
Rank 1
Nate asked on 23 Mar 2011, 04:34 PM
Hello,
        I'm trying to figure out a way to click on the table row that has a variable name (that is it won't be the same each time I run the test). I want to be able to call the "click" method on the table row. Can you guys give me any tips in how to accomplish this? 

7 Answers, 1 is accepted

Sort by
0
Nate
Top achievements
Rank 1
answered on 23 Mar 2011, 04:45 PM
Essentially the HTML I'm trying to target will be of the form-
<TD style="WHITE-SPACE: nowrap" align=left>KnownString</TD>

Where "KnownString" is the information I will have ahead of time.
0
Nate
Top achievements
Rank 1
answered on 23 Mar 2011, 05:06 PM
NVM I figured this one out. Here is how you do it in case someone is wondering-

Element trow = ActiveBrowser.Find.ByContent("KnownString"); //Find the Element in the DOM<br>
Type rowtype = trow.GetType(); //Gets the Type of the Element<br>
rowtype.InvokeMember("Click", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static, null, null, new Object[] { false}); //Calls the Click method with the "false" parameter.
0
Cody
Telerik team
answered on 24 Mar 2011, 11:34 PM
Hi Nate,

There is an easier method:

HtmlTableCell cell = Find.ByExpression<HtmlTableCell>("tagname=td", "textcontent=KnownString");
cell.Click();

All the best,
Cody
the Telerik team
0
Jonathan
Top achievements
Rank 1
answered on 17 Jun 2011, 08:24 PM
Cody,

I'm very new to Telerik and am looking for a similar function to this chain, but maybe taking it a step farther.

I have a radgrid with 3 columns: Name, Description, Delete. This test/screen is one where I Add a new item (with a unique ID) into an alpha sorted field, then click on the name to edit it, then click on the delete icon in the 3rd column to delete it. The entry order is generated in a postback, so I can't guarantee which row my entry will appear on. Thus, recording the delete click will not guarantee me the correct delete icon each time I run it.

The name column is clickable, and I have used the title='Name I entered' to be able to click directly on that item regardless of which row it is on. However, the delete column is just a trash can icon (repeated for each of the dynamically created entries in the radgrid) with an id based on it's current row. If I add another entry above this one, my test step is no longer valid.

I am trying to figure out how to do the following in order to click on the correct delete icon every time.

1. Determine which row contains the item "Name I entered".
2. Click on the Delete icon in column 3 of that row. (The Delete Icon has an id that is generated dynamically in relation to the Name.)

I tried modifying the code snippet you provided here, but I'm not exactly sure how to modify it or where to put it. Do I put it into the EDIT ELEMENT of the actual Delete Icon click step? Please help. This is an important step in every one of my test scripts.

Thanks.

0
Cody
Telerik team
answered on 23 Jun 2011, 06:16 PM
Hi Jonathan,

I think what you are trying to accomplish is best done in code. For example, assume I have an HTML table that looks like this:

<table id="table2" style="width: 300px">
    <tr>
        <td>Name</td>
        <td>Description</td>
        <td>Delete</td>
    </tr>
    <tr>
        <td>Article A01</td>
        <td>Checking Account</td>
        <td><a href="dodelete.html">Delete</a></td>
    </tr>
    <tr>
        <td>Article B01</td>
        <td>Savings Account</td>
        <td><a href="dodelete.html">Delete</a></td>
    </tr>
</table>

First I want to add a the Table element I'll be working with to my Project elements (demonstrated at 4:30 of this video). Then I can use this code to find and click on the Delete icon:

// Copy the table into a local variable to make it easier to work with
HtmlTable myTable = Pages.Tables.Table2Table;
 
// Locate the row we want using text content
HtmlTableRow row = myTable.Find.ByContent<HtmlTableCell>("Article B01").Parent<HtmlTableRow>();
 
// Locate the delete icon (which is going to be just an anchor tag) located in the third column of the current row
HtmlAnchor link = row.Cells[2].Find.ByExpression<HtmlAnchor>("tagname=a");
 
// Now that we've found it, click the delete icon
link.Click();

Greetings,
Cody
the Telerik team
Register today for a live 'What's New in Test Studio R1 2011 SP2' event on Tuesday, July 19 at 2pm EST!

Have you looked at the new Online User Guide for Telerik Test Studio?
0
Zvi
Top achievements
Rank 1
answered on 04 May 2016, 05:10 AM

Hi,

Is there a way to do this by editing the element and binding it to excel sheet with the stand alone app?

Thanks

0
Boyan Boev
Telerik team
answered on 09 May 2016, 08:32 AM
Hello Zvi,

You can do this with data bind find expression.

Please check out this article.

Hope that helps.

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
Nate
Top achievements
Rank 1
Answers by
Nate
Top achievements
Rank 1
Cody
Telerik team
Jonathan
Top achievements
Rank 1
Zvi
Top achievements
Rank 1
Boyan Boev
Telerik team
Share this question
or