Page 1 of 1

Spy doesn't detect the element type.

Posted: Mon Jan 10, 2011 4:48 am
by chandrask
I am testing a Silverlight app. The app has a button with an icon and text within it using data templates. The buttons are created dynamically in a stackpanel and therefore doesn't have any unique id. But the text within everybutton is unique.

I am following the Ron's approach in his RanorexPath screencast. To identify such buttons uniquely the path i am using is "button/text[@caption='Blue']/..". The path when typed in the spy detects the control properly inthe app. When the control is added to the repository, the element shows up as unknown element and not as button. When i append "/button" to the path, the repository marks it as Button element, but the spy doesn't detect the control in the UI and denotes the path as incorrect.

I need to store the element as Button in the repo, so i can invoke the button events from the code behind. When the button is of unknown type, the code behind doesn't allow type casting to Button. How to store the element as button in the repo and still be able to detect the control using spy? An example xpath would help a lot. Thanks!

Re: Spy doesn't detect the element type.

Posted: Mon Jan 10, 2011 11:09 am
by Support Team
You almost had it :)
All you need to do is modify the path you were trying, from "button/text[@caption='Blue']/.." to "button/text[@caption='Blue']/parent::button". By appending the "/button" to the path you were saying look in the parent of the text (which is the button) for a child button which does not exist. The path you had ("button/text[@caption='Blue']/..") says find a button that has a child text element where the caption is equal to 'blue' and then find the parent of the text element. The new path ("button/text[@caption='Blue']/parent::button") says the same thing but qualifies the parent as a button.

Also, you might find the section on the RanoreXPath and UI adapters in the user guide useful:
http://www.ranorex.com/support/user-gui ... xpath.html
http://www.ranorex.com/support/user-gui ... apter.html

Regards,
Ron
Ranorex Team