示例#1
0
        public ComponentScopeLocateResult Find(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions)
        {
            ComponentScopeXPathBuilder builder = new ComponentScopeXPathBuilder(options);

            string xPath = Build(builder, options);

            return(new XPathComponentScopeLocateResult(xPath, scope, searchOptions));
        }
示例#2
0
        protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
        {
            string classCondition = GetClassCondition(options);

            return(builder.
                   WrapWithIndex(x => x.OuterXPath.Any[classCondition]).
                   DescendantOrSelf.ComponentXPath);
        }
示例#3
0
        protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
        {
            string[] conditions = options.Terms.Length > 1
                ? options.Terms.Select(x => $"({x})").ToArray()
                : options.Terms;

            return(builder.WrapWithIndex(x => x.OuterXPath.ComponentXPath[y => y.JoinOr(conditions)]));
        }
示例#4
0
        public ComponentScopeLocateResult Find(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions)
        {
            string labelXPath = new ComponentScopeXPathBuilder(options).
                                WrapWithIndex(x => x.OuterXPath._("label")[y => y.TermsConditionOfContent]);

            IWebElement label = scope.Get(By.XPath(labelXPath).With(searchOptions).Label(options.GetTermsAsString()));

            if (label == null)
            {
                if (searchOptions.IsSafely)
                {
                    return(new MissingComponentScopeLocateResult());
                }
                else
                {
                    throw ExceptionFactory.CreateForNoSuchElement(options.GetTermsAsString(), searchContext: scope);
                }
            }

            string elementId = label.GetAttribute("for");
            IdXPathForLabelAttribute idXPathForLabelAttribute;

            if (string.IsNullOrEmpty(elementId))
            {
                return(new SequalComponentScopeLocateResult(label, new FindFirstDescendantStrategy()));
            }
            else if ((idXPathForLabelAttribute = options.Metadata.Get <IdXPathForLabelAttribute>(x => x.At(AttributeLevels.Component))) != null)
            {
                ComponentScopeLocateOptions idOptions = options.Clone();
                idOptions.Terms = new[] { idXPathForLabelAttribute.XPathFormat.FormatWith(elementId) };
                idOptions.Index = null;

                return(new SequalComponentScopeLocateResult(scope, new FindByXPathStrategy(), idOptions));
            }
            else
            {
                ComponentScopeLocateOptions idOptions = options.Clone();
                idOptions.Terms = new[] { elementId };
                idOptions.Index = null;
                idOptions.Match = TermMatch.Equals;

                return(new SequalComponentScopeLocateResult(scope, new FindByIdStrategy(), idOptions));
            }
        }
示例#5
0
        protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
        {
            string[] conditionalXPathTerms = builder.Options.Terms.
                                             Where(x => (x.StartsWith("[") && x.EndsWith("]")) || x.StartsWith("@")).
                                             ToArray();

            string[] conditionalXPathSelectors = conditionalXPathTerms.
                                                 Select(x => x.StartsWith("@") ? x : x.Substring(1, x.Length - 2)).
                                                 ToArray();

            if (conditionalXPathSelectors.Length > 1)
            {
                conditionalXPathSelectors = conditionalXPathSelectors.
                                            Select(x => $"({x})").
                                            ToArray();
            }

            string conditionalXPath = conditionalXPathSelectors.Any()
                ? builder.WrapWithIndex(x => x.OuterXPath.ComponentXPath[y => y.JoinOr(conditionalXPathSelectors)])
                : null;

            string[] completeXPathSelectors = builder.Options.Terms.
                                              Except(conditionalXPathTerms).
                                              Select(x =>
                                                     acceptableXPathPrefixValues.Any(prefix => x.StartsWith(prefix))
                        ? (options.OuterXPath?.Append(x) ?? x)
                        : ((options.OuterXPath ?? ".//") + x)).
                                              ToArray();

            string completeXPath = completeXPathSelectors.Any()
                ? builder.WrapWithIndex(x => x._($"({string.Join(" | ", completeXPathSelectors)})")).DescendantOrSelf.ComponentXPath
                : null;

            if (conditionalXPath != null && completeXPath != null)
            {
                return($"(({completeXPath}) | ({conditionalXPath}))");
            }
            else
            {
                return(completeXPath ?? conditionalXPath);
            }
        }
示例#6
0
        public ComponentScopeLocateResult Find(ISearchContext scope, ComponentScopeLocateOptions options, SearchOptions searchOptions)
        {
            string labelXPath = new ComponentScopeXPathBuilder(options).
                                WrapWithIndex(x => x.OuterXPath._("label")[y => y.TermsConditionOfContent]);

            IWebElement label = scope.GetWithLogging(By.XPath(labelXPath).With(searchOptions).Label(options.GetTermsAsString()));

            if (label == null)
            {
                return(new MissingComponentScopeFindResult());
            }

            string elementId = label.GetAttribute("for");

            if (string.IsNullOrEmpty(elementId))
            {
                return(new SubsequentComponentScopeFindResult(label, new FindFirstDescendantStrategy()));
            }
            else if (options.Metadata.TryGet(out IdXPathForLabelAttribute idXPathForLabelAttribute))
            {
                ComponentScopeLocateOptions idOptions = options.Clone();
                idOptions.Terms = new[] { idXPathForLabelAttribute.XPathFormat.FormatWith(elementId) };
                idOptions.Index = null;

                return(new SubsequentComponentScopeFindResult(scope, new FindByXPathStrategy(), idOptions));
            }
            else
            {
                ComponentScopeLocateOptions idOptions = options.Clone();
                idOptions.Terms = new[] { elementId };
                idOptions.Index = null;
                idOptions.Match = TermMatch.Equals;

                return(new SubsequentComponentScopeFindResult(scope, new FindByIdStrategy(), idOptions));
            }
        }
示例#7
0
 protected abstract string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options);