Searching in RadGrid

30 posts, 1 answers
  1. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 07 Jun 2010 Link to this post

    Hello,

    I have RadGrid control with several rows and I need to know whether the row with some content is represented.

    Could you, please, answer how may I do this?

    Regards,
    Svetlana
  2. Missing user
    Missing user avatar

    Posted 07 Jun 2010 Link to this post

    Hi Svetlana,

    Thanks for the question and based on yout previous posts, I am assuming you are trying to search rows within a RadGrid like this demo page.

    If so, please try the following coded solution:

    - Highlight and add the grid to your test project (see attached screenshot also for reference):
    - The grid will be added to your project and should look like this in the Elements Explorer Window:
    All Pages -> ASPNETGridDemo -> RadGrid1Div
    - You can then find the cell you want by content, then get the row as the cell's parent. Please see the following coded step example based on the demo page:

    //Add your test methods here...
    [CodedStep("MyCustom Step Description")]
    public void MyCustomStep()
    {
    GridDataCell c = Pages.ASPNETGridDemo.RadGrid1Div.Find.ByExpression<GridDataCell>("TextContent=Chai");
    GridDataItem i = c.Parent<GridDataItem>();
    int r = i.RowIndex;
    }

    The code finds the first row in the demo page by the cell content 'Chai', finds it's parent row, then int r is the row index. There are other properties in GridDataItem i you can use as well.

    Please let us know if you have any questions on the above.

    Best wishes,
    Nelson Sin
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 08 Jun 2010 Link to this post

    Hi Nelson,

    1) I've got an error on execution of "GridDataItem i = c.Parent<GridDataItem>();" string.

    Error text:
    InnerException:
    System.NullReferenceException: Object reference not set to an instance of an object.
       at SFT.New_Test3.New_Test3_CodedStep() in c:\Users\Documents\WebUI Test Studio Projects\SFT\New Test3.aii.cs:line 85

    I tried to replace <GridDataItem> with <Telerik.WebAii.Controls.Html.GridDataItem> but the result the same :(

    2) And seems that "Find.ByExpression<GridDataCell>" expression does not work because I haven't got the error when not matching value was entered.

    Regards,
    Svetlana
  4. Missing user
    Missing user avatar

    Posted 08 Jun 2010 Link to this post

    Hello again Svetlana,

    1) So the example page has that particular implementation and example code was based on it's Dom. Please check your page's implementation and the Dom Explorer to see what kind of html control you would need in your test code.

    For example, you can also use the control HtmlTableRow r = c.Parent<HtmlTableRow>(); since the html tag is also a <TR>

    2) I'm not exactly sure exactly what you mean with your question, but if the GridDataCell is not found by TextContent, then you would need to handle a null reference exception.

    Thanks,
    Nelson
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  5. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 09 Jun 2010 Link to this post

    Hi Nelson,

    When I get 'RowIndex', how can I refer to some sell in the row?

    E.g for the example page http://demos.telerik.com/aspnet-ajax/grid/examples/performance/linq/defaultcs.aspx after the coded step

    [CodedStep("MyCustom Step Description")]
    public void MyCustomStep()
    {
    GridDataCell c = Pages.ASPNETGridDemo.RadGrid1Div.Find.ByExpression<GridDataCell>("TextContent=Chai");
    GridDataItem i = c.Parent<GridDataItem>();
    int r = i.RowIndex;
    }

    we get r=2. How can I refer to 'Quantity per unit' column to ensure that the value is '10 boxes x 20 bags'?

    Thanks,
    Svetlana
  6. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 09 Jun 2010 Link to this post

    Hello Svetlana,

    Since you already have a reference to the row, you simply need to access its DataCells collection and get the desired cell:
    GridDataCell fourthCell = i.DataCells[3];
    Assert.AreEqual("10 boxes x 20 bags", fourthCell.TextContent, "verification failed");


    Hope this helps.

    Greetings,
    Pavel
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  7. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 09 Jun 2010 Link to this post

    Hi Pavel,

    Thank you for the help. Could you, please, tell how can I refer to span element within the sell?

    Source code:
    <tr id="ctl00_StatusGrid_ctl00__0" class="rgRow">
        <td class="rgGroupCol">
            &nbsp;
        </td>
        <td class="NoHorizontalPadding">
            <span title="Not present today" class="StNotPre"></span>
        </td>

    Regards,
    Svetlana
  8. Cody
    Admin
    Cody avatar
    3360 posts

    Posted 09 Jun 2010 Link to this post

    Hello Svetlana,

    What is it you want to do with the span element?

    Assuming 'c' represents the DataGridCell that contains the span element (i.e. just this portion of your sample source code):

    <td class="NoHorizontalPadding">
        <span title="Not present today" class="StNotPre"></span>
    </td>

    then you can locate the span element with this like of code:

    HtmlSpan mySpan = c.Find.ByExpression<HtmlSpan>("title=Not present today");


    Greetings,
    Cody
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  9. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 10 Jun 2010 Link to this post

    Thank you, Cody

    Regards,
    Svetlana
  10. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 13 Jul 2010 Link to this post

    Hello Telerik team,

    I have one more question on Searching in RadGrid.
    There is the following content in Grid data cell:
    <td valign="middle">
            <strong>New</strong>
            <br>
           17/06/2010 to 18/06/2010
    </td>       

    How to find the cell in grid by value in "strong" tag?

    Seems that the value does not included in "TextContent", because

    GridDiv.Find.ByExpression<Telerik.WebAii.Controls.Html.GridDataCell>("TextContent=New 17/06/2010 to 18/06/2010");
    - returns error.

    Could you, please, write correct expression?

    Regards,
    Svetlana                       
  11. Answer
    Cody
    Admin
    Cody avatar
    3360 posts

    Posted 14 Jul 2010 Link to this post

    Hi Svetlana,

    You are very close to the right coded solution. You need to make two modifications:

    1. Use InnerText instead of TextContent. There is a subtle but important difference between the two. TextContent looks only at the text at the same level. Whereas InnerText is recursive. it will be all text combined for the current element and all the text contained in subelements. In your example "New" is the InnerText for just the <strong> element and "17/06/2010 to 18/06/2010" is the TextContent for the <td> element. InnerText is the two concatenated together i.e. "New17/06/2010 to 18/06/2010".
    2. Note that InnerText doesn't have a space between "New" and the date. Thus your second change would be to remove that space resulting in this line of code:
    GridDiv.Find.ByExpression<HtmlTableCell>("InnerText=New17/06/2010 to 18/06/2010");

    Alternatively you could just remove the "New " part (including the space) from your current line of code. Then TextContent would match the date string of your sample.

    Greetings,
    Cody
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Svetlana
    Svetlana avatar
    45 posts
    Member since:
    May 2010

    Posted 15 Jul 2010 Link to this post

    Thank you Cody!
  13. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 16 Aug 2010 Link to this post

    Hello,

    Is it possible to modify searching in the grid and add wait time to perform the action several times till some row isn't found yet? As it may be done in recorded steps (e.g. "Verify the element is visible" -> "Wait for element is visible")

    Thank you in advance.
  14. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 17 Aug 2010 Link to this post

    Hi Nataly,

    Is it the actual element you want to verify, or the text contained in a specific grid item? If you want to assert a row has been added correctly to the grid you can use the items count verification. This shows the number of items in the current page. The other option is to verify the number of total items via the pager text. Screenshots are attached to illustrate both cases. Let me know if that helps.

    Sincerely yours,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  15. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 17 Aug 2010 Link to this post

    Hi Pavel,

    I need to find grid item by content. The content is stored in string variable. This item is added on test execution but I don't want to use grid row's count because real user may add a row while my test is being executed. So I just need to perform 'wait' till grid item with some content appears on the page.

    Thank you.
  16. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 17 Aug 2010 Link to this post

    Hi Nataly,

    In that case I think you need to use Data cell text verification. Note that in order for it to search for a text in a specific cell you need to modify your Find logic settings so that the tag index has higher priority than text content. Otherwise the location of the element is done by its content which does not guarantee that the cell is in specific place in the Grid.

    I hope this helps.

    Regards,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  17. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 17 Aug 2010 Link to this post

    Thank you Pavel.

    Unfortunately, cell's index is unknown and will differ on each test execution. So I can't use this solution. Is there another one?

    Regards,
    Nataly
  18. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 17 Aug 2010 Link to this post

    Hi Nataly,

    If the cell index differs, you can simply use the default behavior which locates the cell by its text. Let me know if this is acceptable solution.

    Greetings,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  19. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 17 Aug 2010 Link to this post

    Thank you Pavel.
    Yes, it is acceptable, but I shall perform 'wait' action till the row appears in grid.
    How can I perform such wait?

    Regards,
    Nataly
  20. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 17 Aug 2010 Link to this post

    Hi Nataly,

    Each verification in WebUI Test Studio has its "wait for" version. In the datacelltext.jpg screenshot attached previously you can see the "wait for" data cell text verifiaction of the Grid Item. Furthermore you can always convert a regular verification to a "wait", by right clicking on the step in question and selecting "Set as Wait".

    Best wishes,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  21. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 17 Aug 2010 Link to this post

    Hi Pavel,

    To add such step as on the screenshot I need to know row's index but the index is unknown beforehand. So seems that I can't use standard recorded step.
    How can I perform 'wait' for cell appearing in the grid in coded step?

    Thank you in advance.
  22. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 17 Aug 2010 Link to this post

    Hello Nataly,

    As I explained previously, if you use the default Find logic, the verification illustrated in the screenshot will locate the cell by its text content, not its id or location in the table. Thus it should work wherever the item appears in the Grid.

    Regards,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  23. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 17 Aug 2010 Link to this post

    Hello Pavel,

    I'm using default Find logic, but this step fails:

    RadGridDataCell: cell [2,0] text verification failed.
    Expected: 'ValueOnExecution', Comparison: 'Is', Actual: 'ValueOnCreation'.

    Could you please tell how can I fix it?

    Thank you in advance
  24. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 18 Aug 2010 Link to this post

    Hi Nataly,

    You can edit the element's find expression via elements explorer. I am attaching screenshots for illustration. Your find expression needs to be similar to the one in the attached file. Let me know if that helps.

    Sincerely yours,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  25. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 18 Aug 2010 Link to this post

    Hi Pavel,

    In my case "text content" and "row index" will be different on each test execution. I can't specify them in element's 'find expression' directly isn't it?
    Is there the possibility to change element's 'find expression' at runtime?

    Thank you
  26. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 18 Aug 2010 Link to this post

    Hi Nataly,

    I am sorry but it seems I have misunderstood you. Now to clarify your requirement, you need to verify a Grid Item by its content, however the content may be different on each execution, and the location of the item may also vary, is that correct?

    If the value is variable, but there is a way to extract it (I am not familiar with your exact scenario, but I am guessing there should be some way to do that), you can locate the element with code in a similar way:
    [CodedStep(@"RadGridDataCell(''): cell content verification ")]
    public void VerifyGridCellContent()
    {
        string cellContent;
        //logic to get the cell content here and assign it to the sting variable
     
        GridDataCell myCell = Find.ByContent<GridDataCell>(cellContent);
        Assert.IsTrue(myCell.CellText == cellContent);
    }

    Note that in order to ensure that the Grid is updated before executing this step it is recommended to add a step that verifies that the control is not longer in insert mode. A screenshot is attached for illustration. This should prevent any synchronization issues where the cell is not yet present on the page.

    Let me know if I am missing something else.

    Greetings,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  27. Nataly
    Nataly avatar
    38 posts
    Member since:
    Aug 2010

    Posted 20 Aug 2010 Link to this post

    Hello Pavel,

    Thank you for the answer. I have one more question: it's strange but I have not "Wait: radGridTable: is not in insert mode" quick task in the list. Could you please tell me what should I do to get it?

    Regards,
    Nataly
  28. Pavel
    Admin
    Pavel avatar
    904 posts

    Posted 20 Aug 2010 Link to this post

    Hello Nataly,

    This quick task is visible when you have CommandItem displayed for the respective TableView. You can use the following code to make a similar verification:
    RadGrid grid = Find.ById<RadGrid>("RadGrid1");
    Wait.For<RadGrid>(myGrid => !myGrid.MasterTable.IsItemInserted, grid, 3000);

    Sincerely yours,
    Pavel
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  29. Lobna
    Lobna avatar
    14 posts
    Member since:
    Jan 2013

    Posted 27 Oct 2013 Link to this post

    I have RadGrid having multiple Rows and I need to filter the data. I use 'allowfiltering' property, but I want to ask is there a way to make filtering automatic, without pressing enter or remove the cursor from the filter textbox?

    Thanks,
  30. Boyan Boev
    Admin
    Boyan Boev avatar
    1039 posts

    Posted 29 Oct 2013 Link to this post

    Hello Lobna,

    Is this somehow connected to Test Studio and automation testing? If so please give us some more detailed information and I will be glad to help you.

    If it is connected to the Silverlight RadGrid control please visit this forum. If it is regarding .NET ASP controls please visit this one.

    Thank you for contacting us.

    Regards,
    Boyan Boev
    Telerik
    Quickly become an expert in Test Studio, check out our new training sessions!
    Test Studio Trainings
Back to Top