Пример #1
0
        public void SelectMenuOption(string menuLocator, string optionLocator)
        {
            Trace.WriteLine(TraceLevelElement + "Select menu option: '" + menuLocator + "'");

            _driver.FindElement(By.XPath(menuLocator)).Info();

            IWebElement lastElement      = _driver.FindElement(By.XPath(menuLocator)).FindElement(By.XPath("./following-sibling::*/li[last()]"));
            Point       lastElementStart = lastElement.Location;

            WaitAndClick(By.XPath(menuLocator));

            BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart);

            _driver.FindElement(By.XPath(optionLocator)).Info();
            Click(By.XPath(optionLocator));

            Thread.Sleep(1000);
        }
Пример #2
0
        public void SelectByValue(string value, SelectByValueType strict = SelectByValueType.Equal)
        {
            IWebElement listDropDown = _driver.FindElement(_listDropDownId);

            IWebElement firstElement = _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[1]"));
            IWebElement lastElement  = _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[last()]"));

            Point fistElementStart = firstElement.Location;
            Point lastElementStart = lastElement.Location;

            //_driver.FindElement(_arrowId).FindElement(By.XPath("./parent::*")).Click();
            _driver.FindElement(_arrowId).Click();

            BasePage.WaitTillStopMoving(_driver, firstElement, fistElementStart);
            BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart);

            fistElementStart = firstElement.Location;
            lastElementStart = lastElement.Location;
            if (strict == SelectByValueType.Equal)
            {
                _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[text() = '" + value + "']")).ScrollIntoView().
                Click();
            }
            else if (strict == SelectByValueType.Contains)
            {
                _driver.FindElement(By.XPath("//*[@id='" + listDropDown.GetAttribute("id") + "']//li[contains(text(), '" + value + "')]")).ScrollIntoView().
                Click();
            }
            else
            {
                throw new Exception("Wrong SelectByValueType");
            }

            try
            {
                BasePage.WaitTillStopMoving(_driver, firstElement, fistElementStart);
                BasePage.WaitTillStopMoving(_driver, lastElement, lastElementStart);
            }
            catch (StaleElementReferenceException)
            {
                Trace.WriteLine(BasePage.TraceLevelElement + "StaleElementReferenceException in SelectByValue of '" + value + "'");
            }
        }