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

Not able to identify Automation ID inside RadGridView cell Template

18 Answers 544 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dilip
Top achievements
Rank 1
Dilip asked on 09 Feb 2015, 10:30 AM
Hi,

Please anyone let us know how to identify the automation id for the control inside the RadGridview cell Template.
Below is the code sample which i tried by giving the automation id but unable to find the id control.

 <telerik:GridViewDataColumn Header="######"
                                            IsSortable="True"
                                            IsReadOnly="True"
                                            UniqueName="#######">
                    <telerik:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding ########}"
                                       AutomationProperties.AutomationId="{Binding Path=#######, StringFormat='##########_{0}'}"></TextBlock>
                        </DataTemplate>
                    </telerik:GridViewDataColumn.CellTemplate>
                </telerik:GridViewDataColumn>

18 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 09 Feb 2015, 02:24 PM
Hello Dilip,

Will it be possible to clarify what your exact scenario is ? Do you want to set custom automation id to an element or probably find the element in a way ? 

Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Dilip
Top achievements
Rank 1
answered on 23 Feb 2015, 09:35 AM
Hello Maya,

I need to find the automation id inside the element of the cell. I hope, i have answered your question. 

Thanks,
Dilip L.
0
Maya
Telerik team
answered on 24 Feb 2015, 12:27 PM
Hi Dilip,

Currently, each element inside the cell will receive a predefined AutomationID that follows the format: 
AutomationProperties.SetAutomationId(childElement, string.Format("CellElement_{0}_{1}", this.OwnerCell.ParentDataControl.Items.IndexOf(this.OwnerCell.ParentRow.Item), this.OwnerCell.Column.DisplayIndex));

As for finding and working with the AutomationID, you can find more information in here: 
1. Use the AutomationID property
2. Coded UI tests : AutomationId or how to find the chose one (control) !

Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 07:24 AM
Hi Maya,

Can I not bind AutomationProperties.AutomationId to some property in XAML ?

<telerik:GridViewDataColumn DataMemberBinding="{Binding Name}" AutomationProperties.AutomationId="{Binding Name}"/> 

Because I do not want using default Automation Id (which contains index)

Regards,
Rajendar. 
0
Maya
Telerik team
answered on 05 Mar 2015, 07:42 AM
Hello Rajendar,

GridViewDataColumn (or any other column) is not a visual element and does not have automation properties. What you can try instead is to work with GridViewCell and set its AutomationId property: 
<Style TargetType="telerik:GridViewCell">
          <Setter Property="AutomationProperties.AutomationId" Value="{Binding Value, RelativeSource={RelativeSource Self}}" />
      </Style>



Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 08:21 AM
Hi Maya,

Thank you for quick responds.

Is anything wrong in my code
-------------------------------------
   <Window.Resources>
        <Style TargetType="telerik:GridViewRow">
            <Setter Property="AutomationProperties.AutomationId" Value="{Binding Value,RelativeSource={RelativeSource Self}}" />
        </Style>    
    </Window.Resources>    
    <Grid x:Name="LayoutRoot" >
        <telerik:RadTreeListView x:Name="radTreeListView"
                            AutoGenerateColumns="False" ShowColumnHeaders="False" >         
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>                
            </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
    </Grid> 
==============
Here name is property.
I am till seeing default automation id only

Regards,
Rajendar.

0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 08:49 AM
Hi Maya,

Thank you for quick responds.

Is anything wrong in my code
-------------------------------------
   <Window.Resources>
        <Style TargetType="telerik:GridViewRow">
            <Setter Property="AutomationProperties.AutomationId" Value="{Binding Name,RelativeSource={RelativeSource Self}}" />
        </Style>    
    </Window.Resources>    
    <Grid x:Name="LayoutRoot" >
        <telerik:RadTreeListView x:Name="radTreeListView"
                            AutoGenerateColumns="False" ShowColumnHeaders="False" >         
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>                
            </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
    </Grid> 
==============
Here name is property.
I am till seeing default automation id only

Regards,
Rajendar.
0
Maya
Telerik team
answered on 05 Mar 2015, 09:02 AM
Hi Rajendar,

When you use the binding:
Value="{Binding Name,RelativeSource={RelativeSource Self}}"

That suggests you have property "Name" of each object of type GridViewRow. 
I am guessing that you want to bind to a property from your business object that has such "Name" property. If so, you do the following: 
<Style TargetType="telerik:GridViewRow">
          <Setter Property="AutomationProperties.AutomationId" Value="{Binding Name}" />
      </Style>



Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 09:12 AM
Hi Maya,

Thanks for your help.

But that is also not working in my case
--------------------------
<Window.Resources>
        <Style TargetType="telerik:GridViewRow" >
            <Setter Property="AutomationProperties.AutomationId" Value="{Binding Name}" />
        </Style>
    </Window.Resources>    
    <Grid x:Name="LayoutRoot" >
        <telerik:RadTreeListView x:Name="radTreeListView"
                            AutoGenerateColumns="False" ShowColumnHeaders="False" >
            <telerik:RadTreeListView.Columns>
                <telerik:GridViewDataColumn DataMemberBinding="{Binding Name}"/>
            </telerik:RadTreeListView.Columns>
        </telerik:RadTreeListView>
    </Grid>
-------------------
Can you please provide any sample application?
Regards,
Rajendar.
0
Maya
Telerik team
answered on 05 Mar 2015, 09:30 AM
Hi Rajendar,

I attach a sample project illustrating the behavior and it seems to work correctly. Do you get different behavior on your side ? 

Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 10:02 AM
Hi Maya,

It is working as expected in RadGridView but not working RadTreeListView.

Why it is not working in RadTreeListView ?
Can you help me to provide unique AutomationId for RadTreeListView Row?

Regards,
Rajendar.
0
Maya
Telerik team
answered on 05 Mar 2015, 10:38 AM
Hi,

Depending on which control you are working with, you need to target GridViewRow or TreeListViewRow. In case of using RadTreeListView, the setting should be:
<Style TargetType="telerik:TreeListViewRow" >
          <Setter Property="AutomationProperties.AutomationId" Value="{Binding Name}" />
      </Style>



Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 11:54 AM
Hi Maya,

Thank you for your help.
Actually I am using  2014.2.0729.45. It is not working in this version. Even if I replace these dlls in sample application which you have provided , CUIT is showing default Automation Id.
Did you fix this issue in latest version. If yes please tell me from which this fix is available?

Regards,
Rajendar.
0
Maya
Telerik team
answered on 05 Mar 2015, 01:30 PM
Hello,

Indeed, there used to be an issue that custom AutomationId and Name properties are not respected and I resolved it in one of our internal builds in September. The fix is available from Q3 2014 release. 

Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Rajendar
Top achievements
Rank 1
answered on 05 Mar 2015, 01:37 PM
Hi Maya,

Thanks for your information.
I have tested in 2014 Q3. It is working fine with Automation Id but look like there an issue with name property.
Did you fix this issue in latest version. If yes please let me the version?

Regards,
Rajendar.
0
Maya
Telerik team
answered on 05 Mar 2015, 03:18 PM
Hi Rajendar,

It turns out the behavior for Name property for TreeListViewRow does not support custom values. I updated that and the fix will be available in our next internal build coming on Monday. 
I also updated your Telerik points. 


Regards,
Maya
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Ivo
Top achievements
Rank 1
answered on 15 Mar 2019, 02:01 PM

Hi Maya,
I am struggling with the AutomationId in RadGriwView in my project. The guys doing automation testing have troubles because the RadGridView is used in more places and in all instances is the same ID (e.g. CellElement_1_0). They want to have different ID to distinguish.  Why the CellElement_1_0 is not prefixed with automation ID that I set for the whole RadGridView element?

I downloaded you example application but still 
I can see AutomationId as : CellElement_1_0

There is used following setter and I wonder why it does not work:
        <Style TargetType="telerik:GridViewRow" >
            <Setter Property="AutomationProperties.AutomationId" Value="{Binding Name}" />
        </Style>

0
Martin Ivanov
Telerik team
answered on 20 Mar 2019, 01:56 PM
Hello Ivo,

The AutomationId of the different elements doesn't get automatically prefixed with its parent AutomationId. Instead, if you want unique Ids for the different gridview cells, you will need to manually set the AutomationId property for them. Then you can apply the unique AutomationId using an implicit style targeting the GridViewCell elements. Similarly, to the code snippet from your last reply.
<Style TargetType="telerik:GridViewCell" >
    <Setter Property="AutomationProperties.AutomationId" Value="{Binding MyUniqueCellName}" />
</Style>

Regards,
Martin Ivanov
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
GridView
Asked by
Dilip
Top achievements
Rank 1
Answers by
Maya
Telerik team
Dilip
Top achievements
Rank 1
Rajendar
Top achievements
Rank 1
Ivo
Top achievements
Rank 1
Martin Ivanov
Telerik team
Share this question
or