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); } }
private ComponentScopeLocateResult ProcessCollectionOfElements(ReadOnlyCollection <IWebElement> elements, ISearchContext scope, ComponentScopeLocateOptions options, SearchOptions searchOptions) { if (options.Index.HasValue) { if (elements.Count <= options.Index.Value) { if (searchOptions.IsSafely) { return(new MissingComponentScopeFindResult()); } else { throw ExceptionFactory.CreateForNoSuchElement( new SearchFailureData { ElementName = $"{(options.Index.Value + 1).Ordinalize()} by script: {Script}", SearchOptions = searchOptions, SearchContext = scope }); } } else { ComponentScopeLocateOptions sequalOptions = options.Clone(); sequalOptions.Index = null; return(new SubsequentComponentScopeFindResult(elements[options.Index.Value], s_sequalStrategy, sequalOptions)); } } else { return(new SubsequentComponentScopeFindResult(elements, s_sequalStrategy)); } }
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)); } }
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)); } }