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(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions) { ComponentScopeXPathBuilder builder = new ComponentScopeXPathBuilder(options); string xPath = Build(builder, options); return new XPathComponentScopeLocateResult(xPath, scope, searchOptions); }
public IWebElement[] GetElements(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); return AtataContext.Current.Driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ => { return predicate(searchOptions).ToArray(); }); }
public IWebElement[] GetElements(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); XPathComponentScopeLocateResult[] xPathResults = GetScopeLocateResults(searchOptions); if (xPathResults.Any()) return xPathResults.Select(x => x.GetAll(xPathCondition)).Where(x => x.Any()).SelectMany(x => x).ToArray(); else return new IWebElement[0]; }
public static By With(this By by, SearchOptions options) { options = options ?? SearchOptions.Unsafely(); ExtendedBy extendedBy = new ExtendedBy(by); extendedBy.Options.Timeout = options.Timeout; extendedBy.Options.RetryInterval = options.RetryInterval; extendedBy.Options.Visibility = options.Visibility; extendedBy.Options.IsSafely = options.IsSafely; return extendedBy; }
private XPathComponentScopeLocateResult[] GetScopeLocateResults(SearchOptions searchOptions) { IWebElement scopeSource = component.ScopeSource.GetScopeElement(component.Parent); if (scopeSource == null && searchOptions.IsSafely) return null; ComponentScopeLocateResult result = strategy.Find(scopeSource, scopeLocateOptions, searchOptions); return ResolveScopeLocateResults(result, scopeSource, searchOptions); }
public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); SearchOptions searchOptionsForElementGet = searchOptions.Clone(); searchOptionsForElementGet.IsSafely = true; IWebElement element = GetElement(searchOptionsForElementGet, xPathCondition); if (element != null && !searchOptions.IsSafely) throw ExceptionFactory.CreateForNotMissingElement(); else return element == null; }
public IWebElement GetElement(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); IWebElement element = AtataContext.Current.Driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ => { return predicate(searchOptions).FirstOrDefault(); }); if (element == null && !searchOptions.IsSafely) throw ExceptionFactory.CreateForNoSuchElement(); else return element; }
public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); bool isMissing = AtataContext.Current.Driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ => { return !predicate(searchOptions).Any(); }); if (!isMissing && !searchOptions.IsSafely) throw ExceptionFactory.CreateForNotMissingElement(); else return isMissing; }
public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); XPathComponentScopeLocateResult[] xPathResults = GetScopeLocateResults(searchOptions); if (xPathResults.Any()) { Dictionary<By, ISearchContext> byScopePairs = xPathResults.ToDictionary(x => x.CreateBy(xPathCondition), x => (ISearchContext)x.ScopeSource); return component.Driver.Try().MissingAll(byScopePairs); } else { return true; } }
protected IWebElement GetScopeElement(SearchOptions searchOptions = null) { if (ScopeLocator == null) throw new InvalidOperationException("ScopeLocator is missing."); searchOptions = searchOptions ?? SearchOptions.Unsafely(); IWebElement element = ScopeLocator.GetElement(searchOptions); if (!searchOptions.IsSafely && element == null) throw ExceptionFactory.CreateForNoSuchElement(ComponentFullName); if (CacheScopeElement) cachedScope = element; return element; }
public ComponentScopeLocateResult Find(IWebElement scope, ComponentScopeLocateOptions options, SearchOptions searchOptions) { By by = By.CssSelector(string.Join(",", options.Terms)); if (options.Index.HasValue) { var elements = scope.GetAll(by.With(searchOptions)); if (elements.Count <= options.Index.Value) throw ExceptionFactory.CreateForNoSuchElement(by: by, searchContext: scope); else return new SequalComponentScopeLocateResult(elements[options.Index.Value], sequalStrategy); } else { return new SequalComponentScopeLocateResult(by, sequalStrategy); } }
public IWebElement GetElement(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); XPathComponentScopeLocateResult[] xPathResults = GetScopeLocateResults(searchOptions); if (xPathResults != null && xPathResults.Any()) { IWebElement element = xPathResults.Select(x => x.Get(xPathCondition)).FirstOrDefault(x => x != null); if (element == null && !searchOptions.IsSafely) throw ExceptionFactory.CreateForNoSuchElement(by: By.XPath(xPathResults.First().XPath + xPathCondition)); else return element; } else { return null; } }
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); }
private XPathComponentScopeLocateResult[] ResolveScopeLocateResults(ComponentScopeLocateResult result, IWebElement scopeSource, SearchOptions searchOptions) { result.CheckNotNull("result"); MissingComponentScopeLocateResult missingResult = result as MissingComponentScopeLocateResult; if (missingResult != null) return null; XPathComponentScopeLocateResult xPathResult = result as XPathComponentScopeLocateResult; if (xPathResult != null) return new[] { xPathResult }; SequalComponentScopeLocateResult sequalResult = result as SequalComponentScopeLocateResult; if (sequalResult != null) { ComponentScopeLocateOptions nextScopeLocateOptions = sequalResult.ScopeLocateOptions ?? scopeLocateOptions; if (sequalResult.ScopeSource != null) { ComponentScopeLocateResult nextResult = sequalResult.Strategy.Find(sequalResult.ScopeSource, nextScopeLocateOptions, searchOptions); return ResolveScopeLocateResults(nextResult, sequalResult.ScopeSource, searchOptions); } else { IWebElement[] nextScopeSources = scopeSource.GetAll(sequalResult.ScopeSourceBy.With(searchOptions)).ToArray(); SearchOptions nextSearchOptions = SearchOptions.SafelyAndImmediately(); var results = nextScopeSources. Select(nextScopeSource => sequalResult.Strategy.Find(nextScopeSource, nextScopeLocateOptions, nextSearchOptions)). Select(nextResult => ResolveScopeLocateResults(nextResult, nextScopeSources[0], nextSearchOptions)). Where(xPathResults => xPathResults != null). SelectMany(xPathResults => xPathResults). ToArray(); if (results.Any()) return results; else if (searchOptions.IsSafely) return null; else throw ExceptionFactory.CreateForNoSuchElement(by: sequalResult.ScopeSourceBy); } } throw new ArgumentException("Unsupported ComponentScopeLocateResult type: {0}".FormatWith(result.GetType().FullName), "result"); }
public XPathComponentScopeLocateResult(string xPath, IWebElement scopeSource, SearchOptions searchOptions) { XPath = xPath; ScopeSource = scopeSource; SearchOptions = searchOptions; }
public IWebElement GetElement(SearchOptions searchOptions = null, string xPathCondition = null) { return element; }
public IWebElement[] GetElements(SearchOptions searchOptions = null, string xPathCondition = null) { return new[] { GetElement(searchOptions, xPathCondition) }; }
public IWebElement GetElement(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = searchOptions ?? SearchOptions.Unsafely(); return locateFunction(searchOptions); }
public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null) { return element == null; }
/// <summary> /// Determines whether the component exists. /// </summary> /// <param name="options">The options. If set to null, then it uses <c>SearchOptions.Safely()</c>.</param> /// <returns>true if the component exists; otherwise, false.</returns> /// <exception cref="NoSuchElementException">The <paramref name="options"/> has IsSafely property equal to false value and the component doesn't exist.</exception> public bool Exists(SearchOptions options = null) { return GetScopeElement(options ?? SearchOptions.Safely()) != null; }
/// <summary> /// Determines whether the component is missing. /// </summary> /// <param name="options">The options. If set to null, then it uses <c>SearchOptions.Safely()</c>.</param> /// <returns>true if the component is missing; otherwise, false.</returns> /// <exception cref="NotMissingElementException">The <paramref name="options"/> has IsSafely property equal to false value and the component exists.</exception> public bool Missing(SearchOptions options = null) { return ScopeLocator.IsMissing(options ?? SearchOptions.Safely()); }