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

Using Relative Xaml Path in Silverlight Automation

5 Answers 109 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 21 Oct 2011, 12:48 AM
I am trying to use relative path in identifying my elements because the absolute path is vulnerable to breaking my scripts. Please I need suggestion on how to write the following absolute path in relative path:

XamlPath=/itemspresenter[0]/stackpanel[0]/contentpresenter[7]/contentcontrol[name=FilterContentControl]/contentpresenter[0]/button[0]/grid[name=ControlGrid]/contentpresenter[name=contentPresenter]/grid[name=LayoutRoot]/textblock[name=FilterCount]

I trid the following and it didn't work:
XamlPath=//grid[name=LayoutRoot]/textblock[name=FilterCount]
or
XamlPath=//*grid[name=LayoutRoot]/textblock[name=FilterCount]

Thanks,

Michael

5 Answers, 1 is accepted

Sort by
0
Stoich
Telerik team
answered on 26 Oct 2011, 01:20 PM
Hi Michael,
    I did a bit of research on this. In your intended relative Xpath name=LayoutRoot refers to a name attribute, correct. In Xpath you need to use the '@' to denote an attribute. name=LayoutRoot looks for a child element with a tagName of "LayoutRoot". Also grid does not seem to be a valid tagName for an element. Highlight the intended element and check it out in the DOM explorer:
http://www.telerik.com/automated-testing-tools/support/documentation/user-guide/elements-menu/dom-explorer.aspx
You need to determine the correct tagName. Here's an example:
The following page contains a grid:
http://demos.telerik.com/aspnet-ajax/grid/examples/performance/linq/defaultcs.aspx
When we check out the grid in the DOM Explorer we can see it's actually a div element with an id of "RadGrid1". The relative Xpath to reach that element looks like this:
//div[@id='RadGrid1']

So most likely your Xpath expression should mostly likely be rewritten like this:
//grid[@name='LayoutRoot']/textblock[@name='FilterCount']
http://www.w3schools.com/XPath/xpath_syntax.asp

Kind regards,
Stoich
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
0
Amit
Top achievements
Rank 1
answered on 21 Dec 2012, 11:12 AM
Hi Telerik Admin,

Can we use double slash("//") like we use in Xpath to traverse the Silverlight elements in depth:
XamlPath=//grid[name=LayoutRoot]/textblock[name=FilterCount]

Thanks,
Amit
0
Stoich
Telerik team
answered on 26 Dec 2012, 10:57 AM
Hi Amit,
no, you won't be able to use "\\" in XamlPath.

And XamlPath needs to follow a liner path. You have to traverse all nodes that lead up to a specific child element. It's best to combine XamlPath with a different Find Logic that gets you to the desired "starting" point, so to say.

For instance if you're looking for the first cell in a Grid named "MyGrid" here's what the Find Expression might look like:
XamlTag=Grid,name=MyGrid,|,XamlPath=/cell[0]

We use the first part of the statement to get to the appropriate reference node. From there we use XamlPath to point to a specific element from its children.

I hope this helps.

Kind regards,
Stoich
the Telerik team
Quickly become an expert in Test Studio, check out our new training sessions!
Test Studio Trainings
0
Amit
Top achievements
Rank 1
answered on 19 Jul 2013, 07:38 AM
hi Telerik Admin,

How can we access parent and grand parents(anywhere upwards) using xamlpath?

Thanks,
Amit
0
Velin Koychev
Telerik team
answered on 22 Jul 2013, 11:56 AM
Hello Amit,

If you already have the XamlPath of the current element, like for example 
XamlPath= /grid[0]/grid[name=LayoutRoot]/frame[automationid=PART_ContentFrame]/textblock[automationid=textBlock]
You can easily find the XamlPath of the parent element:
XamlPath= /grid[0]/grid[name=LayoutRoot]/frame[automationid=PART_ContentFrame]
and the grand parent will be:
XamlPath= /grid[0]/grid[name=LayoutRoot]

As my colleague, Stoich, wrote on his previous post,  XamlPath follows a liner path and you can use it to go backwards just following the "/" signs. 

You might also find this article about DOM navigation very useful. You will find there how to navigate to other elements relative to the current element.

Hope this helps.
 

Regards,
Velin Koychev
Telerik
We've released our first-ever public Test Studio BETA! Download the BETA, install it,
and send us your feedback! Expires mid-August!
Tags
General Discussions
Asked by
Michael
Top achievements
Rank 1
Answers by
Stoich
Telerik team
Amit
Top achievements
Rank 1
Velin Koychev
Telerik team
Share this question
or