Using Relative Xaml Path in Silverlight Automation

6 posts, 0 answers
  1. Michael
    Michael avatar
    2 posts
    Member since:
    Aug 2011

    Posted 20 Oct 2011 Link to this post

    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
  2. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 26 Oct 2011 Link to this post

    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
  3. Amit
    Amit avatar
    4 posts
    Member since:
    Nov 2012

    Posted 21 Dec 2012 Link to this post

    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
  4. Stoich
    Admin
    Stoich avatar
    1 posts

    Posted 26 Dec 2012 Link to this post

    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
  5. Amit
    Amit avatar
    4 posts
    Member since:
    Nov 2012

    Posted 19 Jul 2013 Link to this post

    hi Telerik Admin,

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

    Thanks,
    Amit
  6. Velin Koychev
    Admin
    Velin Koychev avatar
    88 posts

    Posted 22 Jul 2013 Link to this post

    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!
Back to Top