Silver Light Coding Issue.

2 posts, 0 answers
  1. tapan
    tapan avatar
    7 posts
    Member since:
    Jul 2011

    Posted 24 Aug 2011 Link to this post

    Hi,

    We are implementing generic functions for click operations on the Silver light objects.
    But, we are unable to write the proper code in C#, please refer below code and help.

    We have tried below functions without any success.

    1. myManager.ActiveBrowser.Find.ByName<HtmlControl>(objID).Click();  -- Not working
        myManager.ActiveBrowser.SilverlightApps()[0].RefreshVisualTrees();

    2. myManager.ActiveBrowser.SilverlightApps()[0].Find.ByExpression(@"XamlPath=/grid[name=RootElement]/border[name=ChartBorder]/grid[name=ChartAreaGrid]/grid[name=CenterOuterGrid]/grid[name=CenterGrid]/grid[name=CenterInnerGrid]/grid[name=PlotAreaGrid]/scrollviewer[automationid=PlotAreaScrollViewer]/border[0]/grid[0]/scrollcontentpresenter[name=ScrollContentPresenter]/canvas[name=PlotCanvas]/canvas[name=DrawingCanvas]/canvas[0]/canvas[0]/canvas[0]/canvas[0]/path[12]",true).User.HoverOver();

    3.  myManager.ActiveBrowser.SilverlightApps()[0].Find.ByType<ArtOfTest.WebAii.Silverlight.UI.Path>('Uid="66208306"').User.HoverOver();   -- Not Working..

    3. This works when we hover manually on the silver light object to fetch the tool tip value.
    string myToolTipVal = STEPForTestStudioclass.myManager.ActiveBrowser.SilverlightApps()[0].Find.ByAutomationId<TextBlock>("ToolTipTextBlock").TextContent;  --> Works fine.

    But we need some generic function which will click when we pass the object ID/name/Automation ID of the silver light control.

    FYI: While recording and play back it works fine, but we don't want to use that descriptive code but would like to create
    some generic functions if possible.

    Regards
    Tapan
  2. Cody
    Admin
    Cody avatar
    3354 posts

    Posted 25 Aug 2011 Link to this post

    Hello Tapan,

    I can see why you're having so much trouble. I will do my best to clear things up:

    1) To do anything with a Silverlight application you must first get an object to the application. myManager.ActiveBrowser.Find.ByName will only work on HTML elements contained on a webpage. It is not meant to work for Silverlight elements. You have it correct to use myManager.ActiveBrowser.SilverlightApps()[0].

    2) I can't say why that XamlPath doesn't work. it is very long and complicated. There's an example at the very bottom of this page. Generally it's better to break it up so you can shorten it, for example:

    ActiveBrowser.SilverlightApps()[0].Find.ByExpression(new XamlFindExpression("XamlTag=grid", "name=Second", "|", "XamlPath=/checkbox[0]"));

    There may be another reason why it isn't working when expected. For example we cache a local copy of the Visual Tree for performance reasons. If the cached copy is out of sync with the browser, finds like that will fail. If this is the problem performing myManager.ActiveBrowser.SilverlightApps()[0].RefreshVisualTrees(); just before the find will fix it.


    3) The Uid cannot be used in finds. Secondly Find.ByType<ArtOfTest.WebAii.Silverlight.UI.Path> does not accept any parameters at all. You will get a compile error with ByType<ArtOfTest.WebAii.Silverlight.UI.Path>('Uid="66208306"').

    ByType without the <> type specification will accept a string parameter, but that string must be the Xaml tag name to search for:
    ActiveBrowser.SilverlightApps()[0].Find.ByType("TextBlock");

    When you're doing finds in code, we highly recommend using Find.ByExpression for most (if not all) of your finds. How to use this is documented on the page I previously pointed you to.

    This KB article shows you how to get/verify tool tips in both HTML and Silverlight.

    If you have more specific examples that aren't working as expected, I'd be glad to assist figuring out why and how to fix them. I need more details, and hopefully a local repro so i can research the problem and get you a complete answer (instead of having to guess).

    Kind regards,
    Cody
    the Telerik team
    Vote for Telerik Test Studio at the Annual Automation Honors Voting!
Back to Top