Esempio n. 1
0
        /// <summary>
        /// Finds the first <see cref="IWebElement"/> using the given method.
        /// </summary>
        /// <param name="by">The locating mechanism to use.</param>
        /// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns>
        /// <exception cref="NoSuchElementException">If no element matches the criteria.</exception>
        public IWebElement FindElement(By by)
        {
            if (by == null)
            {
                throw new ArgumentNullException("by", "by cannot be null");
            }

            return(by.FindElement(this));
        }
        /// <summary>
        ///     Finds the first element in the page that matches the <see cref="By" /> object
        /// </summary>
        /// <param name="by">By mechanism to find the object</param>
        /// <returns>IWebElement object so that you can interact with that object</returns>
        /// <example>
        ///     <code>
        /// IWebDriver driver = new InternetExplorerDriver();
        /// IWebElement elem = driver.FindElement(By.Name("q"));
        /// </code>
        /// </example>
        public async Task <IWebElement> FindElement(By by, CancellationToken cancellationToken = new CancellationToken())
        {
            if (by == null)
            {
                throw new ArgumentNullException(nameof(by), "by cannot be null");
            }

            return(await by.FindElement(this, cancellationToken));
        }
Esempio n. 3
0
        public WebElementInstance FindElement(SearchContextInstance searchContext)
        {
            if (searchContext == null)
            {
                throw new JavaScriptException(this.Engine, "Error", "A Search Context must be specified.");
            }

            var result = m_by.FindElement(searchContext.SearchContext);

            return(new WebElementInstance(this.Engine.Object.InstancePrototype, result));
        }
Esempio n. 4
0
        public async Task ShouldUseXPathToFindByNameIfDriverDoesNotImplementFindsByName()
        {
            var mockDriver  = new Mock <IOnlyXPath>();
            var mockElement = new Mock <IWebElement>();

            mockDriver.Setup(_ => _.FindElementByXPath(It.Is <string>(x => x == "//*[@name='cheese']"), new CancellationToken())).ReturnsAsync(mockElement.Object);

            By  by      = By.Name("cheese");
            var element = await by.FindElement(mockDriver.Object);

            Assert.AreEqual(mockElement.Object, element);
        }
Esempio n. 5
0
 /// <summary>
 /// Retrieves the web element matching the selector if it exists.
 /// </summary>
 public static bool TryFindElement(this ISearchContext searchContext, By by, out IWebElement element)
 {
     try
     {
         element = by.FindElement(searchContext);
         return(true);
     }
     catch (NoSuchElementException ex)
     {
         Debug.WriteLine($"No such element exception occured: {ex.Message} \n {ex.InnerException}");
         element = null;
         return(false);
     }
 }
 public override IWebElement FindElement(ISearchContext context)
 {
     try
     {
         string id         = control.Locator.FindElement(control.SearchContext).GetAttribute("id");
         string newId      = changeIdStrategy.ChangeId(id);
         By     newLocator = Id(newId);
         return(newLocator.FindElement(context));
     }
     catch (Exception)
     {
         return(null);
     }
 }
Esempio n. 7
0
        public async Task ShouldUseFindsByNameToLocateElementsByName()
        {
            var mockDriver  = new Mock <IAllDriver>();
            var mockElement = new Mock <IWebElement>();
            List <(Task <IWebElement>, string, CancellationToken)> queue = new List <(Task <IWebElement>, string, CancellationToken)>();

            mockDriver.Setup(_ => _.FindElementByName(It.Is <string>(x => x == "cheese"), new CancellationToken())).ReturnsAsync(mockElement.Object);

            By  by      = By.Name("cheese");
            var element = await by.FindElement(mockDriver.Object);

            Assert.AreEqual(mockElement.Object, element);
            mockDriver.Verify(x => x.FindElementByName("cheese", new CancellationToken()), Times.Once);
        }
Esempio n. 8
0
        public static void BringIntoView(this IWebDriver driver, By by)
        {
            var          element     = by.FindElement(driver);
            var          jsExec      = driver.InjectJQuery();
            ICoordinates coordinates = ((ILocatable)element).Coordinates;
            Point        point       = coordinates.LocationInViewport;

            if (driver.IsClickObstructed(point, element))
            {
                jsExec.ExecuteScript("function scrollIntoView(el) {"
                                     + "var offsetTop = $(el).offset().top;"
                                     + "var adjustment = Math.max(0,( $(window).height() - $(el).outerHeight(true) ) / 2);"
                                     + "var scrollTop = offsetTop - adjustment;"
                                     + "$('html,body').animate({"
                                     + "scrollTop: scrollTop"
                                     + "}, 0);"
                                     + "} scrollIntoView(arguments[0]);", element);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Finds the first element in the page that matches the <see cref="By"/> object
 /// </summary>
 /// <param name="by">By mechanism to find the element</param>
 /// <returns>IWebElement object so that you can interction that object</returns>
 public IWebElement FindElement(By by)
 {
     return by.FindElement(this);
 }
Esempio n. 10
0
 /// <summary>
 /// Finds the first element in the page that matches the <see cref="By"/> object.
 /// </summary>
 /// <param name="by">By mechanism.</param>
 /// <returns>IWebElement object so that you can interction that object.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// IWebElement elem = driver.FindElement(By.Name("q"));
 /// </code>
 /// </example>
 public IWebElement FindElement(By by)
 {
     return by.FindElement(new Finder(driver, elementHandle));
 }
Esempio n. 11
0
 /// <summary>
 /// Finds the first element in the page that matches the <see cref="By"/> object.
 /// </summary>
 /// <param name="by">By mechanism for finding the element.</param>
 /// <returns>IWebElement object so that you can interction that object.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// IWebElement elem = driver.FindElement(By.Name("q"));
 /// </code>
 /// </example>
 public IWebElement FindElement(By by)
 {
     return by.FindElement(new Finder(this, new SafeInternetExplorerWebElementHandle()));
 }
Esempio n. 12
0
 public IWebElement FindElement(By @by)
 {
     return(@by.FindElement(containerLocator.FindElement(parentSearchContext)));
 }
Esempio n. 13
0
 public IWebElement FindElement(By by)
 {
     return(by.FindElement(this));
 }
Esempio n. 14
0
 public IWebElement FindElement(By mechanism)
 {
     return(mechanism.FindElement(new ElementFinderContext(currentNode, webBrowser)));
 }
Esempio n. 15
0
        public IWebElement FindElement(By by)
        {
            ISearchContext ctx = CreateSearchContext(_my);

            return(by.FindElement(ctx));
        }
 /// <summary>
 /// Finds the first element in the page that matches the <see cref="By"/> object.
 /// </summary>
 /// <param name="by">By mechanism for finding the element.</param>
 /// <returns>IWebElement object so that you can interction that object.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// IWebElement elem = driver.FindElement(By.Name("q"));
 /// </code>
 /// </example>
 public IWebElement FindElement(By by)
 {
     return(by.FindElement(new Finder(this, new SafeInternetExplorerWebElementHandle())));
 }
Esempio n. 17
0
 public override IWebElement FindElement(ISearchContext context)
 {
     return(By.FindElement(context));
 }
Esempio n. 18
0
        /// <summary>
        /// Finds the first <see cref="IWebElement"/> using the given method. 
        /// </summary>
        /// <param name="by">The locating mechanism to use.</param>
        /// <returns>The first matching <see cref="IWebElement"/> on the current context.</returns>
        /// <exception cref="NoSuchElementException">If no element matches the criteria.</exception>
        public IWebElement FindElement(By by)
        {
            if (by == null)
            {
                throw new ArgumentNullException("by", "by cannot be null");
            }

            return by.FindElement(this);
        }
Esempio n. 19
0
 /// <summary>
 /// Finds the first element in the page that matches the <see cref="By"/> object.
 /// </summary>
 /// <param name="by">By mechanism.</param>
 /// <returns>IWebElement object so that you can interction that object.</returns>
 /// <example>
 /// <code>
 /// IWebDriver driver = new InternetExplorerDriver();
 /// IWebElement elem = driver.FindElement(By.Name("q"));
 /// </code>
 /// </example>
 public IWebElement FindElement(By by)
 {
     return(by.FindElement(new Finder(driver, elementHandle)));
 }