public bool IsMissing(SearchOptions searchOptions = null, string xPathCondition = null) { searchOptions = ResolveSearchOptions(searchOptions); SearchOptions quickSearchOptions = SearchOptions.SafelyAtOnce(); quickSearchOptions.Visibility = searchOptions.Visibility; bool isMissing = component.Driver.Try(searchOptions.Timeout, searchOptions.RetryInterval).Until(_ => { XPathComponentScopeLocateResult[] xPathResults = GetScopeLocateResults(quickSearchOptions); if (xPathResults.Any()) { Dictionary <By, ISearchContext> byScopePairs = xPathResults.ToDictionary(x => x.CreateBy(xPathCondition), x => (ISearchContext)x.ScopeSource); return(component.Driver.Try(TimeSpan.Zero).MissingAll(byScopePairs)); } else { return(true); } }); if (!searchOptions.IsSafely && !isMissing) { throw ExceptionFactory.CreateForNotMissingElement(component.ComponentFullName); } else { return(isMissing); } }
private XPathComponentScopeLocateResult[] ResolveScopeLocateResult(ComponentScopeLocateResult result, IWebElement scopeSource, SearchOptions searchOptions) { result.CheckNotNull(nameof(result)); if (result is MissingComponentScopeLocateResult missingResult) { return(new XPathComponentScopeLocateResult[0]); } if (result is XPathComponentScopeLocateResult xPathResult) { return new[] { xPathResult } } ; if (result is SequalComponentScopeLocateResult sequalResult) { ComponentScopeLocateOptions nextScopeLocateOptions = sequalResult.ScopeLocateOptions ?? scopeLocateOptions; if (sequalResult.ScopeSource != null) { ComponentScopeLocateResult nextResult = sequalResult.Strategy.Find(sequalResult.ScopeSource, nextScopeLocateOptions, searchOptions); return(ResolveScopeLocateResult(nextResult, sequalResult.ScopeSource, searchOptions)); } else { IWebElement[] nextScopeSources = scopeSource.GetAll(sequalResult.ScopeSourceBy.With(searchOptions)).ToArray(); SearchOptions nextSearchOptions = SearchOptions.SafelyAtOnce(); var results = nextScopeSources. Select(nextScopeSource => sequalResult.Strategy.Find(nextScopeSource, nextScopeLocateOptions, nextSearchOptions)). Select(nextResult => ResolveScopeLocateResult(nextResult, nextScopeSources[0], nextSearchOptions)). Where(xPathResults => xPathResults != null). SelectMany(xPathResults => xPathResults). ToArray(); if (results.Any()) { return(results); } else if (searchOptions.IsSafely) { return(new XPathComponentScopeLocateResult[0]); } else { throw ExceptionFactory.CreateForNoSuchElement(by: sequalResult.ScopeSourceBy); } } } throw new ArgumentException($"Unsupported {nameof(ComponentScopeLocateResult)} type: {result.GetType().FullName}", nameof(result)); } }
public override string ToString() { StringBuilder builder = new StringBuilder(ComponentFullName); IWebElement scope = GetScopeElement(SearchOptions.SafelyAtOnce()); if (scope != null) { builder.AppendLine().Append(scope.ToDetailedString()); } return(builder.ToString()); }
protected override string GetParameterAsString(IWebElement element) { string elementId = element.GetAttribute("id"); if (!string.IsNullOrEmpty(elementId)) { IWebElement scope = component.ScopeSource.GetScopeElement(component, SearchOptions.SafelyAtOnce()); IWebElement label = scope.Get( By.XPath($".//label[@for='{elementId}']"). SafelyAtOnce()); if (label != null) { return(label.Text); } } return(element.Get(By.XPath("ancestor::label").AtOnce()).Text); }
public override string GetXPathCondition(object parameter, TermOptions termOptions) { IWebElement scope = component.ScopeSource.GetScopeElement(component, SearchOptions.SafelyAtOnce()); IWebElement label = scope.Get( By.XPath($".//label[{TermResolver.CreateXPathCondition(parameter, termOptions)}]"). SafelyAtOnce(). Label(TermResolver.ToDisplayString(parameter))); if (label != null) { string elementId = label.GetAttribute("for"); if (!string.IsNullOrEmpty(elementId)) { return($"[@id='{elementId}']"); } } return($"[ancestor::label[{TermResolver.CreateXPathCondition(parameter, termOptions)}]]"); }
protected virtual bool GetIsVisible() { return(GetScope(SearchOptions.SafelyAtOnce())?.Displayed ?? false); }
protected virtual bool GetIsPresent() { return(GetScope(SearchOptions.SafelyAtOnce()) != null); }
private XPathComponentScopeLocateResult[] ResolveScopeLocateResult(ComponentScopeLocateResult result, IWebElement scopeSource, SearchOptions searchOptions) { result.CheckNotNull(nameof(result)); if (result is MissingComponentScopeLocateResult missingResult) { return(new XPathComponentScopeLocateResult[0]); } if (result is XPathComponentScopeLocateResult xPathResult) { return new[] { xPathResult } } ; if (result is SequalComponentScopeLocateResult sequalResult) { ComponentScopeLocateOptions nextScopeLocateOptions = sequalResult.ScopeLocateOptions ?? scopeLocateOptions; if (sequalResult.ScopeSources?.Count() == 1) { return(ExecuteStrategyAndResolveResults(sequalResult.Strategy, sequalResult.ScopeSources.First(), nextScopeLocateOptions, searchOptions)); } else { IEnumerable <IWebElement> nextScopeSources = sequalResult.ScopeSourceBy != null ? scopeSource.GetAll(sequalResult.ScopeSourceBy.With(searchOptions)) : sequalResult.ScopeSources; SearchOptions nextSearchOptions = SearchOptions.SafelyAtOnce(); var results = nextScopeSources. Select(nextScopeSource => ExecuteStrategyAndResolveResults(sequalResult.Strategy, nextScopeSource, nextScopeLocateOptions, nextSearchOptions)). Where(xPathResults => xPathResults != null). SelectMany(xPathResults => xPathResults). ToArray(); if (results.Any()) { return(results); } else if (searchOptions.IsSafely) { return(new XPathComponentScopeLocateResult[0]); } else { throw ExceptionFactory.CreateForNoSuchElement( new SearchFailureData { ElementName = component.ComponentFullName, By = sequalResult.ScopeSourceBy, SearchOptions = searchOptions, SearchContext = scopeSource }); } } } throw new ArgumentException($"Unsupported {nameof(ComponentScopeLocateResult)} type: {result.GetType().FullName}", nameof(result)); }
protected virtual bool GetIsVisibleInViewPort() { IWebElement element = GetScope(SearchOptions.SafelyAtOnce()); return(element != null && element.Displayed && Script.Execute <bool>(IsInViewPortScript, element)); }