Click on Table Row with a Variable Name

8 posts, 0 answers
  1. Nate
    Nate avatar
    32 posts
    Member since:
    Feb 2011

    Posted 23 Mar 2011 Link to this post

    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? 
  2. Nate
    Nate avatar
    32 posts
    Member since:
    Feb 2011

    Posted 23 Mar 2011 Link to this post

    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.
  3. Nate
    Nate avatar
    32 posts
    Member since:
    Feb 2011

    Posted 23 Mar 2011 Link to this post

    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.
  4. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 24 Mar 2011 Link to this post

    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
  5. Jonathan
    Jonathan avatar
    1 posts
    Member since:
    May 2011

    Posted 17 Jun 2011 Link to this post

    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.

  6. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 23 Jun 2011 Link to this post

    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?
  7. Zvi
    Zvi avatar
    2 posts
    Member since:
    Apr 2016

    Posted 04 May in reply to Cody Link to this post

    Hi,

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

    Thanks

  8. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 08 May Link to this post

    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
     
Back to Top