コード例 #1
0
        private WatiN.Core.Element FindFieldByLabel(string locator, Scope scope)
        {
            WatiN.Core.Element field = null;

            var label = WatiNScope(scope).Labels.First(Find.ByText(new Regex(locator)));

            if (label != null)
            {
                var isVisible = Constraints.IsVisible(scope.ConsiderInvisibleElements);

                if (!string.IsNullOrEmpty(label.For))
                {
                    field = WatiNScope(scope).Elements.First(Find.ById(label.For) & isVisible);
                }

                if (field == null)
                {
                    field = label.Elements.First(Constraints.IsField() & isVisible);
                }
            }
            return(field);
        }
コード例 #2
0
        public WatiN.Core.Element FindField(string locator, Scope scope)
        {
            var field = FindFieldByLabel(locator, scope);

            if (field == null)
            {
                var isField = Constraints.IsField();

                var byIdOrName    = Find.ById(locator) | Find.ByName(locator);
                var byPlaceholder = Find.By("placeholder", locator);
                var radioButtonOrCheckboxByValue = (Constraints.OfType <RadioButton>() | Constraints.OfType <CheckBox>()) & Find.ByValue(locator);
                var byPartialId = Constraints.WithPartialId(locator);

                var hasLocator = byIdOrName | byPlaceholder | radioButtonOrCheckboxByValue | byPartialId;

                var isVisible = Constraints.IsVisible(scope.ConsiderInvisibleElements);

                var candidates = WatiNScope(scope).Elements.Filter(isField & hasLocator & isVisible);
                field = candidates.FirstMatching(byIdOrName, byPlaceholder, radioButtonOrCheckboxByValue, byPartialId);
            }

            return(field);
        }