Exemple #1
0
        protected IWebElement GetItemElement(object parameter, bool isSafely = false, string xPathCondition = null)
        {
            ExecuteTriggers(TriggerEvents.BeforeAccess);

            string itemConditionXPath = ItemElementFindStrategy.GetXPathCondition(parameter, ValueTermOptions);

            itemConditionXPath += xPathCondition;

            IWebElement element = ScopeLocator.GetElement(SearchOptions.Safely(isSafely), itemConditionXPath);

            ExecuteTriggers(TriggerEvents.AfterAccess);

            return(element);
        }
Exemple #2
0
        public XPathComponentScopeFindResult[] Execute(StrategyScopeLocatorExecutionData executionData)
        {
            ISearchContext scopeContext = executionData.ScopeSource.GetScopeContext(
                executionData.Component,
                SearchOptions.Safely(executionData.IsSafely));

            if (scopeContext is null)
            {
                return(new XPathComponentScopeFindResult[0]);
            }

            foreach (var unit in executionData.LayerUnits)
            {
                XPathComponentScopeFindResult[] xPathResults = Execute(unit.Strategy, scopeContext, unit.ScopeLocateOptions, unit.SearchOptions);

                if (!xPathResults.Any())
                {
                    return(xPathResults);
                }

                IWebElement element = xPathResults.Select(x => x.Get()).FirstOrDefault(x => x != null);

                if (element is null)
                {
                    if (!executionData.IsSafely)
                    {
                        XPathComponentScopeFindResult firstResult = xPathResults.First();

                        throw ExceptionFactory.CreateForNoSuchElement(
                                  new SearchFailureData
                        {
                            ElementName   = $"layer of {executionData.Component.ComponentFullName}",
                            By            = By.XPath(firstResult.XPath),
                            SearchOptions = firstResult.SearchOptions
                        });
                    }
                    else
                    {
                        return(new XPathComponentScopeFindResult[0]);
                    }
                }

                scopeContext = unit.ScopeContextResolver.Resolve(element);
            }

            return(Execute(executionData.FinalUnit.Strategy, scopeContext, executionData.FinalUnit.ScopeLocateOptions, executionData.FinalUnit.SearchOptions));
        }
Exemple #3
0
 /// <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(OnMissing(options ?? SearchOptions.Safely()));
 }
Exemple #4
0
 /// <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);
 }
Exemple #5
0
 /// <summary>
 /// Gets the <see cref="IWebElement"/> instance that represents the scope HTML element.
 /// Also executes <see cref="TriggerEvents.BeforeAccess" /> and <see cref="TriggerEvents.AfterAccess" /> triggers.
 /// </summary>
 /// <param name="options">The search options.
 /// If set to <c>null</c>, then it uses <c>SearchOptions.Safely()</c>.</param>
 /// <returns>The <see cref="IWebElement"/> instance of the scope.</returns>
 public IWebElement GetScope(SearchOptions options = null)
 {
     return(GetScopeElement(options ?? SearchOptions.Safely()));
 }
Exemple #6
0
 /// <summary>
 /// Gets the <see cref="ISearchContext"/> instance that represents the scope search context
 /// (where to find the children of this component).
 /// Also can execute <see cref="TriggerEvents.BeforeAccess" /> and <see cref="TriggerEvents.AfterAccess" /> triggers.
 /// </summary>
 /// <param name="searchOptions">
 /// The search options.
 /// If set to <see langword="null"/>, then it uses <c>SearchOptions.Safely()</c>.</param>
 /// <returns>The <see cref="ISearchContext"/> instance of the scope context.</returns>
 public ISearchContext GetScopeContext(SearchOptions searchOptions = null)
 {
     return(OnGetScopeContext(searchOptions ?? SearchOptions.Safely()));
 }