Exemple #1
0
 public ControlFinder()
 {
     if (_descriptionContainerList == null)
     {
         _descriptionContainerList = DescriptionAttributeUtil.GetDescriptionValues <ControlType>();
     }
 }
Exemple #2
0
 public ControlFinder(string source)
 {
     Source = source;
     if (_descriptionContainerList == null)
     {
         _descriptionContainerList = DescriptionAttributeUtil.GetDescriptionValues <ControlType>();
     }
 }
Exemple #3
0
        public BaseControl FindControl(string controlName, string controlFrame = null)
        {
            IElement control;
            By       webControlLocator;

            if (string.IsNullOrEmpty(controlName) && string.IsNullOrEmpty(controlFrame))
            {
                throw new ArgumentException("The control and container names must not have a null or empty value.");
            }

            if (!string.IsNullOrEmpty(controlName) && string.IsNullOrEmpty(controlFrame))
            {
                control = SearchElement(Source, controlName);

                webControlLocator =
                    By.XPath(string.Format(GenericControlXPath, control.GetAttribute(DOMAttributes.ControlNameAttribute)));
            }
            else if (string.IsNullOrEmpty(controlName) && !string.IsNullOrEmpty(controlFrame))
            {
                control = SearchElementContainer(Source, controlFrame);

                controlName = controlFrame;

                webControlLocator =
                    By.XPath(string.Format(GenericControlXPath, control.GetAttribute(DOMAttributes.ControlNameAttribute)));
            }
            else
            {
                // The control has a container
                IElement container = SearchElementContainer(Source, controlFrame);
                control = SearchElement(container.OuterHtml, controlName);

                webControlLocator =
                    By.XPath(string.Format(GenericContainerControlXPath,
                                           container.GetAttribute(DOMAttributes.ControlNameAttribute),
                                           control.GetAttribute(DOMAttributes.ControlNameAttribute)));
            }

            // The control type value of the custom attribute from the HTML element.
            string controlType = control.GetAttribute(DOMAttributes.ControlTypeAttribute);

            // The enum value from the ControlType enum.
            ControlType enumControlTypeValue = DescriptionAttributeUtil.GetValueFromDescription <ControlType>(controlType);

            // The web control Type from the current assembly.
            Type webControlType = AssemblyHelper.GetTypeFromAssembly(enumControlTypeValue.ToString(), _currentAssembly);

            // the WebControl instance.
            dynamic webControl = Activator.CreateInstance(webControlType, controlName, webControlLocator,
                                                          Config.ImplicitTimeoutInSeconds);

            return(webControl);
        }