Inheritance: ISearchContext
        /// <summary>
        /// Initializes a new instance of the <see cref="TestWebElement" /> class.
        /// </summary>
        /// <param name="settings">The settings.</param>
        /// <param name="element">The element.</param>
        /// <param name="selfSelector">The self selector.</param>
        /// <param name="parent">The parent.</param>
        /// <param name="selfLookup">The self lookup.</param>
        public TestWebElement(TestSettings settings, IWebElement element, By selfSelector, ISearchContext parent, Func <ISearchContext, IWebElement> selfLookup)
        {
            _settings      = settings;
            _selfSelector  = selfSelector;
            _element       = element;
            _origin        = DetermineOrigin(_element);
            _elementLookup = () =>
            {
                //Has the element become stale and been nulled
                if (_element == null)
                {
                    //Console.WriteLine("resolving: {0}", selfSelector);
                    _element = selfLookup(parent);

                    var currentUri = DetermineOrigin(_element);

                    if (_origin != null)
                    {
                        if (!MatchesOriginStrictnessLevel(currentUri))
                        {
                            var message =
                                $"Navigation occured between resolving elements. Original element was resolved on {_origin} but a StaleElementReferenceException caused it to be re-resolved on {currentUri}. You can control the sensitivty of this check by changing SamePageOriginStrictness in the settings passed to the TestWebDriver";
                            throw new InvalidElementStateException(message);
                        }
                    }
                }

                return(_element);
            };
            _context = new TestSearchContext(_settings, selfSelector, this, _elementLookup);
        }
示例#2
0
 public TestWebDriver(IWebDriver driver, TestSettings settings, ITestOutputHelper testOutputHelper)
 {
     _driver           = driver;
     Settings          = settings;
     _context          = new TestSearchContext(Settings, null, _driver, null);
     _testOutputHelper = testOutputHelper;
 }