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)); }
protected override string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options) { string classCondition = GetClassCondition(options); return(builder. WrapWithIndex(x => x.OuterXPath.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.OuterXPath.ComponentXPath[y => y.JoinOr(conditions)])); }
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)); } }
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); } }
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)); } }
protected abstract string Build(ComponentScopeXPathBuilder builder, ComponentScopeLocateOptions options);