Ejemplo n.º 1
0
        public int SetTextValue(String windowName, String objName, String value)
        {
            AutomationElement childHandle = GetObjectHandle(windowName,
                                                            objName);

            if (!utils.IsEnabled(childHandle))
            {
                childHandle = null;
                throw new XmlRpcFaultException(123,
                                               "Object state is disabled");
            }
            object valuePattern = null;

            try
            {
                if (childHandle.Current.ControlType == ControlType.ComboBox)
                {
                    AutomationElement o          = null;
                    ArrayList         objectList = new ArrayList();
                    ControlType[]     type       = new ControlType[1] {
                        ControlType.Edit
                    };
                    // NOTE: Using "*" for object name, which returns the first
                    // matching Edit control type
                    o = utils.InternalGetObjectHandle(childHandle,
                                                      "*", type, ref objectList);
                    if (o != null)
                    {
                        childHandle = o;
                    }
                    objectList = null;
                }
                // Reference: http://msdn.microsoft.com/en-us/library/ms750582.aspx
                if (!childHandle.TryGetCurrentPattern(ValuePattern.Pattern,
                                                      out valuePattern))
                {
                    childHandle.SetFocus();
                    SendKeys.SendWait(value);
                }
                else
                {
                    ((ValuePattern)valuePattern).SetValue(value);
                }
            }
            catch (Exception ex)
            {
                LogMessage(ex);
                if (ex is XmlRpcFaultException)
                {
                    throw;
                }
                else
                {
                    throw new XmlRpcFaultException(123,
                                                   "Unhandled exception: " + ex.Message);
                }
            }
            finally
            {
                childHandle  = null;
                valuePattern = null;
            }
            return(1);
        }