/// <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(); }
/// <summary> /// Returns the list of items in the dropdown. /// </summary> /// <returns></returns> public virtual IList <string> GetItems() { return(OptionsElements.Select(oe => oe.Text).ToList()); }