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

Silver Light Coding Issue.

1 Answer 74 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
tapan
Top achievements
Rank 1
tapan asked on 24 Aug 2011, 04:17 PM
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

1 Answer, 1 is accepted

Sort by
0
Cody
Telerik team
answered on 25 Aug 2011, 11:05 PM
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!
Tags
General Discussions
Asked by
tapan
Top achievements
Rank 1
Answers by
Cody
Telerik team
Share this question
or