// Scrolling methods
        public void ScrollToElement(By locator)
        {
            AssertDisposed();
            WaitForElementPresent(locator);
            IWebElement element = WrappedDriver.FindElement(locator);

            WrappedDriver.ExecuteJavaScript <object>("arguments[0].scrollIntoView(true);", element);
            Thread.Sleep(100);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// FindMe() selects the iframe, and searches for the element.  Once found the IWebElement
        /// is stored in the WrappedElement for future use
        /// Waits an amount of time specified by the timeoutMs value.
        /// </summary>
        /// <returns></returns>
        public IWebElement FindMe()
        {
            //wait for all ajax requests to finish
            WrappedDriver.WaitForAjax(_timeoutMs);

            //If the element was already found, and has not gone stale, return the previously found IWebElement
            if (IsStale())
            {
                WrappedDriver.SwitchTo().DefaultContent();
                //if the container is not null, use it as the root element (search in descendents)
                if (_container != null)
                {
                    //find the root element using the container's findMe
                    var root = _container.FindMe();
                    //select an iframe if necessary
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }

                    //if FindHidden is false, only find visible elements
                    if (!FindHidden)
                    {
                        _webelement = root.FindVisibleElement(_by);
                    }
                    else
                    {
                        //find any element, even if its hidden
                        _webelement = root.FindElement(_by);
                    }
                }
                else
                {
                    //select the iframe if appropriate
                    if (_frame != null)
                    {
                        WrappedDriver.SwitchTo().Frame(_frame.FindMe());
                    }
                    //find hidden elements if appropriate
                    if (!FindHidden)
                    {
                        _webelement = WrappedDriver.FindVisibleElement(_by);
                    }
                    //find any element including hidden ones
                    else
                    {
                        _webelement = WrappedDriver.FindElement(_by);
                    }
                }
            }
            //highlight the element so the user can see what element was found
            //_webelement.Highlight();
            return(_webelement);
        }
        public void PickFromDropDown(string dropdown, string text)
        {
            string dropdownXpath = dropdownXPathFirstPart + dropdown + dropdownXPathSecondPart;

            WrappedDriver.FindElement(By.XPath(dropdownXpath)).Click();
            string xpath = "//span[contains(text(),'" + text + "')]";

            WrappedDriver.FindElement(By.XPath(xpath)).Click();
            NewPersonText.Click();
            //string optionsXPath = "//span[@role='option']";
            //var options = WrappedDriver.FindElements(By.XPath(optionsXPath));
            //options.FirstOrDefault(e => e.Text.Contains(text)).Click();
        }
Ejemplo n.º 4
0
 public void LogOut()
 {
     // Log out
     WrappedDriver.FindElement(By.XPath("//*[@id='header']/div[2]/div/div/nav/div[2]/a")).Click();
 }
 /// <summary>
 /// If overriding don't forget to call base.Load() or make sure to
 /// assign the WrappedElement.
 /// </summary>
 /// <returns></returns>
 public virtual ILoadableComponent Load()
 {
     WrappedElement = WrappedDriver.FindElement(By);
     return(this);
 }
 ReadOnlyCollection <IWebElement> ISearchContext.FindElements(By by)
 {
     return((ReadOnlyCollection <IWebElement>)(WrappedDriver.FindElement(new ByEx(by))));
 }
 IWebElement ISearchContext.FindElement(By by)
 {
     return(WrappedDriver.FindElement(new ByEx(by)));
 }
Ejemplo n.º 8
0
 public IWebElement Find(ByEx byEx)
 {
     return(WrappedDriver.FindElement(byEx));
 }
 public IWebElement Find(ByEx byEx)
 {
     WrappedDriver.WaitForPageLoad();
     return(WrappedDriver.FindElement(byEx));
 }
Ejemplo n.º 10
0
        /// <summary>
        /// FindMe() selects the iframe, and searches for the element.  Once found the IWebElement
        /// is stored in the WrappedElement for future use
        /// Waits an amount of time specified by the timeoutMs value.
        /// </summary>
        /// <returns></returns>
        public IWebElement FindMe()
        {
            //wait for all ajax requests to finish
            WrappedDriver.WaitForAjax(TimeoutMs);

            //look for a non-null reference in the cache
            if (WebElement == null)
            {
                WebElement = WebElementCache.GetCachedElement(this.ToString(), Index);
            }

            //If the element was already found, and has not gone stale, return the previously found IWebElement

            if (IsStale())
            {
                var stopwatch = Stopwatch.StartNew();
                WrappedDriver.SwitchTo().DefaultContent();
                //if the container is not null, use it as the root element (search in descendents)
                if (Container != null)
                {
                    //find the root element using the container's findMe
                    var root = Container.FindMe();
                    //select an iframe if necessary
                    if (Frame != null)
                    {
                        Logger.Log($"Select frame {Frame}");

                        WrappedDriver.SwitchTo().Frame(Frame.WaitForMe());
                    }

                    //if FindHidden is false, only find visible elements
                    if (!FindHidden)
                    {
                        Logger.Log($"Finding visible {this}");

                        WebElement = root.FindVisibleElement(By);
                    }
                    else
                    {
                        Logger.Log($"Finding {this}");

                        //find any element, even if its hidden
                        WebElement = root.FindElement(By);
                    }
                }
                else
                {
                    //select the iframe if appropriate
                    if (Frame != null)
                    {
                        Logger.Log($"Selecting frame {Frame}");

                        WrappedDriver.SwitchTo().Frame(Frame.WaitForMe());
                    }
                    //find hidden elements if appropriate
                    if (!FindHidden)
                    {
                        Logger.Log($"Finding visible {this}");

                        WebElement = WrappedDriver.FindVisibleElement(By);
                    }
                    //find any element including hidden ones
                    else
                    {
                        Logger.Log($"Finding {this}");

                        WebElement = WrappedDriver.FindElement(By);
                    }
                }
                stopwatch.Stop();
                Logger.Log($"{this} found after {stopwatch.ElapsedMilliseconds} ms");
                //save the found element to the cache
                WebElementCache.SaveElementToCache(WebElement, this.ToString(), Index);
            }

            return(WebElement);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Adds the new associated products.
        /// </summary>
        /// <param name="productName">Name of the product.</param>
        /// <returns></returns>
        public virtual AssociatedProductsVariantsComponent AddNewAssociatedProducts(
            string productName)
        {
            var productNameSelector = By.CssSelector("#SearchProductName");
            var searchSelector      = By.CssSelector("#search-products");
            var saveSelector        = By.CssSelector("*[name='save']");

            var currentWindowHandle = WrappedDriver.CurrentWindowHandle;
            var windowHandles       = WrappedDriver.WindowHandles;
            var newWindowHandle     = default(string);

            AddNewAssociatedProductElement.Click();

            // Wait for the new window to appear.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(5))
            .Until(d => newWindowHandle = d.WindowHandles
                                          .Except(windowHandles)
                                          .FirstOrDefault());

            // Switch to new window.
            WrappedDriver.SwitchTo().Window(newWindowHandle);

            var productNameEl = new InputElement(
                WrappedDriver.FindElement(
                    productNameSelector));

            var searchElement = WrappedDriver.FindElement(searchSelector);

            var productsGrid = pageObjectFactory.PrepareComponent(
                new KGridComponent <AssociatedProductsVariantsComponent>(
                    new BaseKendoConfiguration(),
                    By.CssSelector("#products-grid"),
                    pageObjectFactory,
                    WrappedDriver,
                    this));

            var saveElement = WrappedDriver.FindElement(saveSelector);

            productNameEl.SetValue(productName);
            searchElement.Click();

            // Wait until ajax request finishes.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => !productsGrid.IsBusy());

            // Select the first product that appears.
            var firstCheckbox = productsGrid
                                .GetCell(0, 0)
                                .FindElement(By.TagName("input"));

            var checkbox = new CheckboxElement(firstCheckbox);

            checkbox.Check(true);

            // Save.
            saveElement.Click();

            // Wait until the window handle no longer exists.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .Until(d => !d.WindowHandles.Contains(newWindowHandle));

            // Switch back to the main window.
            WrappedDriver.SwitchTo().Window(currentWindowHandle);

            // Wait for the ajx request to finish.
            WrappedDriver
            .Wait(TimeSpan.FromSeconds(10))
            .UntilChain(d => AssociatedProductsGridComponent.IsBusy())
            .UntilChain(d => !AssociatedProductsGridComponent.IsBusy());

            return(this);
        }
Ejemplo n.º 12
0
 private IWebElement GetResultsCountDiv()
 {
     return(WrappedDriver.FindElement(By.Id("b_tween")));
 }
Ejemplo n.º 13
0
 private IWebElement GetGoButton()
 {
     return(WrappedDriver.FindElement(By.Id("sb_form_go")));
 }
Ejemplo n.º 14
0
 private IWebElement GetSearchBox()
 {
     return(WrappedDriver.FindElement(By.Id("sb_form_q")));
 }