예제 #1
0
        /// <summary>
        /// Sets the selected item.
        /// </summary>
        /// <param name="value"></param>
        /// <param name="stringComparison"></param>
        public virtual void SetSelectedItem(string value,
                                            StringComparison stringComparison = StringComparison.Ordinal)
        {
            // Check if already set.
            var isAlreadySet = String.Equals(
                GetSelectedItem(),
                value,
                stringComparison);

            if (isAlreadySet)
            {
                return;
            }

            Expand();

            var newValEl = OptionsElements
                           .FirstOrDefault(e => String.Equals(
                                               e.TextHelper().InnerText,
                                               value,
                                               stringComparison));

            if (newValEl == null)
            {
                throw new NoSuchElementException();
            }

            if (configuration.ControlWithKeyboardInsteadOfMouse)
            {
                // Check if the element is above or below.
                var currentValEl = OptionsElements.First(
                    e => e.Classes().Contains("k-state-selected"));

                var currentIndex = currentValEl.GetIndexRelativeToSiblings();
                var newIndex     = newValEl.GetIndexRelativeToSiblings();

                // Determine which key to use and how many times to press it.
                var difference = currentIndex - newIndex;
                var magnitude  = Math.Abs(difference);
                var key        = difference > 0 ? Keys.Up : Keys.Down;

                // Keep sending the key needed.
                for (var i = 0; i < magnitude; i++)
                {
                    ContainerElement.SendKeys(key);
                }

                ContainerElement.SendKeys(Keys.Enter);
            }
            else
            {
                newValEl.Click();
            }

            WaitForAnimationEnd();
        }
예제 #2
0
        /// <summary>
        /// Collapses this widget if not already collapsed.
        /// </summary>
        protected virtual void Close()
        {
            if (IsExpanded)
            {
                // Use keyboard or mouse depending on config.
                if (configuration.ControlWithKeyboardInsteadOfMouse)
                {
                    ContainerElement.SendKeys(Keys.Escape);
                }
                else
                {
                    ContainerElement.Click();
                }

                WaitForAnimationEnd();
            }
        }