public ComponentScopeLocateResult Find(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions)
        {
            string labelXPath = new ComponentScopeXPathBuilder(options).
                WrapWithIndex(x => x.Descendant._("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");
            if (string.IsNullOrEmpty(elementId))
            {
                return new SequalComponentScopeLocateResult(label, new FindFirstDescendantStrategy());
            }
            else
            {
                ComponentScopeLocateOptions idOptions = options.Clone();
                idOptions.Terms = new[] { elementId };
                idOptions.Index = null;
                idOptions.Match = TermMatch.Equals;

                return new SequalComponentScopeLocateResult(scope, new FindByIdStrategy(), idOptions);
            }
        }
        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.Descendant.ComponentXPath[y => y.JoinOr(conditionalXPathSelectors)])
                : null;

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

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

            if (conditionalXPath != null && outerXPath != null)
                return $"(({outerXPath}) | ({conditionalXPath}))";
            else
                return outerXPath ?? conditionalXPath;
        }
        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);
        }
Esempio n. 4
0
        protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
        {
            string idCondition = string.IsNullOrWhiteSpace(options.IdXPathFormat)
                ? builder.TermsConditionOf("id")
                : builder.JoinOr(options.Terms.Select(term => options.IdXPathFormat.FormatWith(term)));

            return builder.WrapWithIndex(x => x.Descendant.Any[idCondition]).DescendantOrSelf.ComponentXPath;
        }
        protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
        {
            string classCondition = GetClassCondition(options);

            return builder.
                WrapWithIndex(x => x.Descendant.Any[classCondition]).
                DescendantOrSelf.ComponentXPath;
        }
        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.Descendant.ComponentXPath[y => y.JoinOr(conditions)]);
        }
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.
         WrapWithIndex(x => x.Descendant._("dl/dt")[y => y.TermsConditionOfContent]).
         FollowingSibling._("dd").DescendantOrSelf.ComponentXPath;
 }
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.
         WrapWithIndex(x => x.Descendant.Any[y => y.TermsConditionOf("name")]).
         DescendantOrSelf.ComponentXPath;
 }
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.
         WrapWithIndex(x => x.Descendant._("td").WhereIndex(columnIndex).DescendantOrSelf.ComponentXPath);
 }
 protected abstract string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options);
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.
         WrapWithIndex(x => x.Descendant.ComponentXPath[y => y.TermsConditionOfContent]);
 }
Esempio n. 12
0
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.WrapWithIndex(options.Index.Value, x => x.Descendant.ComponentXPath);
 }
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.
         WrapWithIndex(x => x.Descendant._("fieldset")[y => y._("legend")[z => z.TermsConditionOfContent]]).
         DescendantOrSelf.ComponentXPath;
 }
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.DescendantOrSelf.ComponentXPath;
 }
 protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options)
 {
     return builder.Self.Any;
 }