locked
Find control with focus and perform action RRS feed

  • Question

  • So I have a case where I cannot uniquely identify controls (edit boxes) in a window. My idea to bypass this is using SendKeys and tab to the correct object, then searching for it using the HasFocus property. But how do I move from there? What I want to do is to modify the text property of the text box.

     

    SilverlightEdit new_edit = new SilverlightEdit(this.UIMap.window);
               
                UITestControlCollection c = new_edit.FindMatchingControls();
               
                foreach (UITestControl contr in c)

                    if (contr.HasFocus == true)
                    {

                        //How to use contr object for setting the Text property?
                    }

    Tuesday, February 22, 2011 3:38 PM

Answers

  • I'll answer myself here, the properties of a UITestControl are accesible through SetProperty.
    • Marked as answer by mattias_s Wednesday, February 23, 2011 9:46 AM
    Wednesday, February 23, 2011 9:46 AM

All replies

  • HasFocus property returns a bool indicating whether a particular control hasfocus or not.

     

    you can count on number of tabs to reach to the desired textbox and do a sendkeys{"you text"} and to move away you can use sendkeys{Tab}.


    ---Mark this post if this Answers or Helps---
    Cheers
    FunnyFox
    Tuesday, February 22, 2011 3:53 PM
  • Correct, I have verified the code above so I know what it does. But the question was how to access the Text property of the control which has focus. Is there any way to do that?
    Tuesday, February 22, 2011 3:56 PM
  • I'll answer myself here, the properties of a UITestControl are accesible through SetProperty.
    • Marked as answer by mattias_s Wednesday, February 23, 2011 9:46 AM
    Wednesday, February 23, 2011 9:46 AM