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); } }
public ComponentScopeLocateResult Find(ISearchContext scope, ComponentScopeLocateOptions options, SearchOptions searchOptions) { int?columnIndex = GetColumnIndex(scope, options, searchOptions); if (columnIndex == null) { if (searchOptions.IsSafely) { return(new MissingComponentScopeFindResult()); } else { throw ExceptionFactory.CreateForNoSuchElement( new SearchFailureData { ElementName = $"\"{options.GetTermsAsString()}\" column header", SearchOptions = searchOptions, SearchContext = scope }); } } IComponentScopeFindStrategy nextStrategy = CreateColumnIndexStrategy(columnIndex.Value); return(new SubsequentComponentScopeFindResult(scope, nextStrategy)); }
public ComponentScopeLocateResult Find(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions) { var headers = scope.GetAll(By.XPath(headerXPath).With(searchOptions).OfAnyVisibility()); var headerNamePredicate = options.Match.GetPredicate(); int?columnIndex = headers. Select((x, i) => new { x.Text, Index = i }). Where(x => options.Terms.Any(term => headerNamePredicate(x.Text, term))). Select(x => (int?)x.Index). FirstOrDefault(); if (columnIndex == null) { if (searchOptions.IsSafely) { return(new MissingComponentScopeLocateResult()); } else { throw ExceptionFactory.CreateForNoSuchElement(options.GetTermsAsString(), searchContext: scope); } } return(new FindByColumnIndexStrategy(columnIndex.Value).Find(scope, options, searchOptions)); }
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(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions) { var headers = scope.GetAll(By.XPath(headerXPath).OfAnyVisibility()); var headerNamePredicate = options.Match.GetPredicate(); int? columnIndex = headers. Select((x, i) => new { Text = x.Text, Index = i }). Where(x => options.Terms.Any(term => headerNamePredicate(x.Text, term))). Select(x => (int?)x.Index). FirstOrDefault(); if (columnIndex == null) { if (searchOptions.IsSafely) return new MissingComponentScopeLocateResult(); else throw ExceptionFactory.CreateForNoSuchElement(options.GetTermsAsString(), searchContext: scope); } return new FindByColumnIndexStrategy(columnIndex.Value).Find(scope, options, searchOptions); }
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)); } }