Retrieving Images/Textbox/radio from Datagrid

9 posts, 0 answers
  1. sivaraj
    sivaraj avatar
    12 posts
    Member since:
    Feb 2011

    Posted 05 Jul 2011 Link to this post

    I was using Webaii version and used the datagrid to access the images by using the below (Code snippet)

     
    objApplication = Browser.SilverlightApps().GetApp(0);
    objApplication.Connect();

    DataGrid 
    objDataGrid =  objApplication.Find.ByName<DataGrid>("dataGrid");
    objDataGrid.Rows[0].Cells[0].Find.ByName<RadioButton>().User.Click();

    However when i try using the above one with the latest version (), I got warnings as the Rows are depericiated and use RowElements instead. But RowElements are not FrameworkElement type and hence i couldnt fetch the image/textbox/radio inside the Cell. It would be great if you can give a sample to fetch the above using the latest methods (upgraded).

    Also if am continue using the above method (using rows), will this method be removed from the framework in later releases. Is there any harm using the depreciated methods in the latest framework if it is working fine in my cases.

    Thanks in advance.
  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 05 Jul 2011 Link to this post

    Hi Sivaraj,
         you can rewrite your code like this:
    objApplication = Browser.SilverlightApps().GetApp(0);
    objApplication.Connect();
     
    DataGrid  objDataGrid =  objApplication.Find.ByName<DataGrid>("dataGrid");
    objDataGrid.RowElements[0].CellElements[0].CastAs<DataGridCell>().Find.Find.ByName<RadioButton>("someName").User.Click();
    A major difference is that CellElements[0] will return IDataGridCell (an Interface) and not a "normal" DataGridCell element. We've implemented this in order to improve code reusability for WPF/Silverlight testing.
    One consequence is that you'll need to cast IDataGridCell to a Silverlight DataGridCell (unless you're doing WPF testing in which case you'll have to cast it to a WPF DataGridCell).

    That being said I agree that the IDataGridCell interface should contain a Find method (which would have eliminated the need for casting in the above logic). I've logged this as a bug, you can track its progress here:
    http://www.telerik.com/support/pits.aspx#/public/test-studio/6750

    Kind regards,
    Stoich
    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?
  3. sivaraj
    sivaraj avatar
    12 posts
    Member since:
    Feb 2011

    Posted 02 Aug 2011 Link to this post


    Hi while I am using the following code in version 2011.1.609.0 it will shows the exception "object reference not set to an instance of object"

    objApplication = Browser.SilverlightApps().GetApp(0);
    objApplication.Connect();
       
    RadGridView objRadGrid =  objApplication.Find.ByName<RadGridView>("radgridview");
    int i = objRadGrid.Rows.Count

    Similarly I am not able to proceed with objRadGrid.Rows[5].Cells[4].text.

    So I am using the following work around.

    RadGridView objRadGrid =  objApplication.Find.ByName<RadGridView>("radgridview"); 
    GridViewRow objRows = objRadGrid.Find.AllByType<GridViewRow>();
    int i = objRows.Count

    But the above code returns only the visible rows count. I am not able to proceed for the invisible rows. objRows.ScrollToVisible() , click, etc all are not working.

    Help me to proceed on this.

    Thanks and Regards,
    Siva
  4. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 02 Aug 2011 Link to this post

    Hi Sivaraj,

    You do not need objApplication.Connect();. Rewrite your code that gets the application to this:

    SilverlightApp theApp = ActiveBrowser.SilverlightApps()[0];


    You are correct that you can only get the visible rows from a RadGridView of a Silverlight application. This is a limitation of the VisualTree contained in the Silverlight engine. That is the only thing we are able to see in Silverlight.  You can make a grid scroll using the ScrollViewer element with code like this:

    ScrollViewer scroller = myLB.Find.ByType<ScrollViewer>();

    scroller.InvokeMethod("ScrollToVerticalOffset", scrollPos);

    Greetings,
    Cody
    the Telerik team
    Check out the Test Studio roadmap to find out more about the new performance testing functionality coming in our R2 2011 release this September!

    Have you looked at the new Online User Guide for Telerik Test Studio?
  5. sivaraj
    sivaraj avatar
    12 posts
    Member since:
    Feb 2011

    Posted 11 Aug 2011 Link to this post

    What about the exception ?
  6. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 11 Aug 2011 Link to this post

    Hello Sivaraj,

    I need more details about the exception you are getting. Which line of code is throwing the exception? Can you provide the complete stack trace?

    Greetings,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
  7. emma
    emma avatar
    4 posts
    Member since:
    May 2011

    Posted 02 Sep 2011 Link to this post

    We have silverlight application having quite a few datagrid to display data in database.  
    Is it possible to get total number of rows (including not visible rows) in datagrid in silverlight application?
    There is a property of selectedIndex of datagrid...is there a way to find out the index of a dataGridRow?
    Thanks a lot.
  8. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 08 Sep 2011 Link to this post

    Hello Emma,

    I am sorry but we don't currently have a direct method for discovering how many rows a Silverlight DataGrid contains. The technical problem is that a DataGrid is normally bound to an "ItemsSource" object which is a collection of anything. Since we have no way of knowing what this object is, we have no method of discovering how many items are in the collection.

    Maybe your developers can add a hidden field/element somewhere in the UI which contains the count you need?

    If you have a GridViewRow you can get at it's index like this:

    row.Index;


    Regards,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
  9. emma
    emma avatar
    4 posts
    Member since:
    May 2011

    Posted 08 Sep 2011 Link to this post

    Thanks very much for the quick response.  We will talk to the developers about the solution that you've suggested. 
Back to Top