Пример #1
0
        protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
        {
            string classCondition = GetClassCondition(options);

            return(builder.
                   WrapWithIndex(x => x.OuterXPath.Any[classCondition]).
                   DescendantOrSelf.ComponentXPath);
        }
Пример #2
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)]));
        }
Пример #3
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);
            }
        }