Delete Row in a HTML Table

8 posts, 1 answers
  1. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 27 Jun 2012 Link to this post

    Hello Telerik Team

        I Have a Issue to delete a row from a Html Table
    This is How My table looks like in a webpage,  I can create new by clicking the create new link , If i Add a new row its added in the bottom
    for example I added Name:"Pf3"

    Name Description Additional Info Action
    pf1 pf11
    pf2 pf22
    pf3 pf33
    This is my coded step to delete the third one "pf3"
    [CodedStep(@"Click 'DeleteLink3'")]
            public void testlising_CodedStep()
            {
                HtmlTable table = Find.ByExpression<HtmlTable>("TagIndex=table:0");
                Assert.IsNotNull(table);   
                
                HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=pf3, tagname=td");
                HtmlTableCell cell = row.Cells[3];
                HtmlAnchor a = cell.Find.ByExpression<HtmlAnchor>("innertext=~delete","tagname=a");
                
                   
            }

    I did not get the result, If i go and check in debug watch window, in the row it says Null

    Table -> Row[1] -> Cells[0] = " "
    Please its Urgent, in my test.

  2. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 27 Jun 2012 Link to this post

    Hello Siva,

    There are a few mistakes in the line that declares the HtmlTableRow. You're missing quotes, you should indicate a partial match for InnerText, and the TagName should be tr:

    //This only applies if it's the first Table on the page
    HtmlTable table = Find.ByExpression<HtmlTable>("TagIndex=table:0");
    Assert.IsNotNull(table);  
                 
    HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=~pf3", "tagname=tr");
    HtmlTableCell cell = row.Cells[3];
     
    HtmlAnchor a = cell.Find.ByExpression<HtmlAnchor>("innertext=~delete","tagname=a");
    a.Click();


    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  3. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 28 Jun 2012 Link to this post

    Thanks a Lot Anthony, Its working good,
  4. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 28 Jun 2012 Link to this post

    Hello Anthony

     The Test Seems Like Passed with HTML Table  Row Delete,
    I got Failed in the following situation , I have two test Tests 1- > Creation 2 -> Deletion

    In the 3rd Test  i Invoke Test1 (Creation) some steps(for Edit) then Test2(deletion), 
    I got Fail at the end step deletion

    Failure Information:
    ~~~~~~~~~~~~~~~
    Exception thrown executing coded step: '[testlising_CodedStep] : @"Click 'DeleteLink3''.
    InnerException:
    System.NullReferenceException: Object reference not set to an instance of an object.

    In the Debug window The HTML Table is Null., May i know why the table is Null
  5. Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 29 Jun 2012 Link to this post

    Hello Siva,

    There's no way for me to tell why the table is null without more information. As I mentioned in the comments in my code sample, the HtmlTable declaration will only work if it's the first table on the page (it's being found by table tag and index of 0).

    If your target table has some other unique attribute, like ID or Name, it's best to change the Find.ByExpression statement to use that attribute instead.

    The step failure details will give you further insight into the step failure, including a copy of the DOM tree on failure. Inspect that and determine the most reliable way you should be locating your table.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  6. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 29 Jun 2012 Link to this post

    Hello Anthony,

     I verified Table TAgIndex, also Used Another Attribute tagname;

    The Thing is, The Same Test If  I run Separately its deleting a row. If I call that test as a step in another test,its failed, I verified the DOM Image and DOM tree, it is not updated from the previous page
      // Click 'PortfoliosLink'( I want to go to 'PortfoliosLink' page, but in DOM Image and DOM tree its still in the Previos Page)

    I tried with this ActiveBrowserRefresh and go to the page that i want. But still its not updated in DOM
    I added this code step to go to the page that i want and then Delete step

     [CodedStep(@"Click 'PortfoliosLink'")]
            public void SWR387_DeletePortFolio_CodedStep()
            {
                ActiveBrowser.Refresh();
                 Pages.MembershipAdministration.PortfoliosLink.Click();
                 Pages.MembershipAdministration.PortfoliosLink.Refresh();
              }



               [CodedStep(@"Click 'DeleteLink3'")]
            public void testlising_CodedStep()
            {
                 HtmlTable table = Find.ByExpression<HtmlTable>("TagIndex=table:0","TagName=table");
                Assert.IsNotNull(table);
         
                HtmlTableRow row = table.Find.ByExpression<HtmlTableRow>("innertext=~"+ Data["PortFolioName"].ToString() ,"tagname=tr");
               // HtmlTableCell ce = row.Cells[1];
                HtmlTableCell cell = row.Cells[3];
                HtmlAnchor a = cell.Find.ByExpression<HtmlAnchor>("innertext=~Delete","tagname=a");
                a.Click();
                   
            }


    If I do the Step By Step Debug in testList, Finally the Result is Passed, If I run in Test List Its Failed,
    Do I need to use wait on element or something , if so where should i apply.
  7. Answer
    Anthony
    Admin
    Anthony avatar
    19 posts

    Posted 29 Jun 2012 Link to this post

    Hello Siva,

    You can refresh the DOM tree like this:

    ActiveBrowser.RefreshDomTree();

    Just before the coded step that clicks Delete, try inserting a Wait For Exists step based on the element that takes the longest to load on that particular page.

    Beyond those suggestions I'll need to see the issue first-hand to continue troubleshooting. If your project files are too sensitive for a public forum, attach them (within a zip file) to a support ticket, which is confidential.

    All the best,
    Anthony
    the Telerik team
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
  8. Siva
    Siva avatar
    28 posts
    Member since:
    Apr 2012

    Posted 03 Jul 2012 Link to this post

    Hello Anthony

     Thank you for your suggestion
    wait for exists worked for me.
Back to Top