How to find control if control have no Automation Id and Name

Apr 1, 2010 at 7:02 AM

hi all,

 

whenever i am going to find contol with the help of VisualUIAVerify.sometime i could't find the control Automation id and Name

 than i am implementing the code to find the control with the help of x-axis and y-axis cordinate.

Any other solution we have?

Apr 1, 2010 at 7:27 AM

Hi

 

if the control is not visible the UIAutomation parts of this control is not implemented and so you can't find them.

As I know there is no way for you to find these elements using UIAutomation and so no way to use white for this.

 

What can you do!

 

You need access to the developer, and the developer has to implement the parts for UIAutomation for the control to make it visible for White and VisualUIAVerify/UISpy.

look for that for example: Controls and UIAutomation

 

Throndorin

 

 

Apr 1, 2010 at 7:48 AM

1) If you can't see the control with VisualUIAVerify or UISpy, neither White nor MS UI Automation in general will help you. You need to approach developers as Throndorin suggested.

2) If you SEE the control with VisualUIAVerify or UISpy, but the control doesn't have [unique] AutomationId or Name, you can get the control by ClassName etc.

3) Also, you can get it using tricky geometry and X, Y.

            // To get an AutomationElement.FromPoint, we should hit exactly at the point
            // that is within AutomationElement bounding rectangle.
            // This is a problem if the label is small enough to hide in the rectangle's corner.
            // So we try several point along the rectangle's medium line.

     public string StringFromPoint(double x, double y) {
            AutomationElement ae = null;
            ae = AutomationElement.FromPoint(new Point(x, y));
            string myString = "";
            myString = ae.Current.Name.ToString();
            return myString;
        }

or do whatever you want with ae, like

     UIItem whiteUIItem = new UIItem(ae, window.ActionListener);

4) If you have a bunch of controls but their names are changing, you can try to get them by Index.

5) If the bunch of controls can be organized by index in a sort of a regular structure like array of arrays (e.g. rows x columns), you can build a List or Collection from them.

 

Apr 1, 2010 at 8:03 AM
MichaelPoliakov wrote:

2) If you SEE the control with VisualUIAVerify or UISpy, but the control doesn't have [unique] AutomationId or Name, you can get the control by ClassName etc.

 

 

In fact this is a reason for me to talk with the developer to add an automationID and name, because the class name might change but an automationId should never change.

such things can make developing Tests much easier.

Our developer define for every visisble Element an automationId since we have talked about this problem.

Throndorin

Apr 1, 2010 at 11:18 AM

Throndorin,

sure having AutomationId is a good practice. However, most often I face cases 3-5 (e.g. a bunch of text labels in a pseudo-grid), so I either pick the needed label via X, Y or convert an indexed collection to a set of records.