/// <summary>
        /// Uses the Webdriver's support classes, with a better selecting method.
        /// </summary>
        public void SelectEdamCheese(string url)
        {
            try
            {
                _driver = Browser.GetFirefoxDriver();

                _driver.Navigate().GoToUrl(url);

                var select = new SelectElement(_driver.FindElement(By.TagName("select")));
                select.DeselectAll();
                select.SelectByText("Edam");
            }
            catch (OpenQA.Selenium.Support.UI.UnexpectedTagNameException ex)
            {
                Console.WriteLine("An exception occured, while selecting the tag: " + ex.Message);
                Debug.WriteLine("An exception occured, while selecting the tag: " + ex.Message);
            }
            catch (System.InvalidOperationException ex)
            {
                Console.WriteLine("An Invalid operations exception occured: " + ex.Message);
                Debug.WriteLine("An Invalid operations exception occured: " + ex.Message);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("An exception occured: " + ex.Message);
                Debug.WriteLine("An exception occured: " + ex.Message);
            }
            finally
            {
                _driver.Quit();
            }
        }
        public void ShouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections()
        {
            IWebElement   element        = driver.FindElement(By.Name("multi"));
            SelectElement elementWrapper = new SelectElement(element);

            elementWrapper.DeselectAll();
            IList <IWebElement> returnedOptions = elementWrapper.AllSelectedOptions;

            Assert.AreEqual(0, returnedOptions.Count);
        }
Beispiel #3
0
 /// <summary>
 /// Selects some options from a multi-select element
 /// </summary>
 /// <param name="select">the select element</param>
 /// <param name="option">the options to select</param>
 public static void SelectOptions(IWebElement select, IEnumerable<string> options)
 {
     SelectElement sourceSelect = new SelectElement(select);
     if (sourceSelect.IsMultiple)
     {
         sourceSelect.DeselectAll();
     }
     foreach (string option in options)
     {
         sourceSelect.SelectByText(option);
     }
 }
Beispiel #4
0
 public void ShouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelections()
 {
     IWebElement element = driver.FindElement(By.Name("selectomatic"));
     SelectElement elementWrapper = new SelectElement(element);
     elementWrapper.DeselectAll();
 }
Beispiel #5
0
        public void ShouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections()
        {
            IWebElement element = driver.FindElement(By.Name("multi"));
            SelectElement elementWrapper = new SelectElement(element);
            elementWrapper.DeselectAll();
            IList<IWebElement> returnedOptions = elementWrapper.AllSelectedOptions;

            Assert.AreEqual(0, returnedOptions.Count);
        }
Beispiel #6
0
        public static void SetValue(string controlString, string value)
        {
            DbConnectionStringBuilder _control = new DbConnectionStringBuilder();
            _control.ConnectionString = controlString;

            if (! _control.ContainsKey("type"))
            {
                throw new ArgumentOutOfRangeException("type","The control type has not been implemented in SetValue()");
            }

            IWebElement _element = GetElement(controlString);

            string text;

            switch (_control["type"].ToString().ToLower())
            {
                case "input":
                case "text":
                case "typetext":
                    _element.SendKeys(value ?? string.Empty);
                    WaitForAsyncPostBackToComplete();
                    break;

                case "select":
                    // if the value to set is empty, ignore it.
                    if (!string.IsNullOrEmpty(value))
                    {
                        WaitForAsyncPostBackToComplete();
                        SelectElement selectElement = new SelectElement(_element);
                        selectElement.DeselectAll();
                        selectElement.SelectByText(value);

                        WaitForAsyncPostBackToComplete();
                    }
                    break;

                case "checkbox":
                    // if the value to set is empty, ignore it.
                    if (!string.IsNullOrEmpty(value))
                    {
                        bool isChecked;
                        bool.TryParse(value, out isChecked);
                        // _document.CheckBox(_control.WatinAttribute).Checked = isChecked;

                        WaitForAsyncPostBackToComplete();
                    }
                    break;

                case "radiobutton":
                    // if the value to set is empty, ignore it.
                    if (!string.IsNullOrEmpty(value))
                    {
                        // _document.RadioButton((_control.WatinAttribute) && Find.ByValue(value)).Checked = true;
                        WaitForAsyncPostBackToComplete(); ;
                    }
                    break;

                case "fileupload":
                    //  _document.FileUpload(_control.WatinAttribute).Set(value);
                    WaitForAsyncPostBackToComplete();
                    break;

                default:
                    throw new NotImplementedException("The control type has not been implemented in Stax.Controller.Watin SetValue()");
            }
        }
        public void SelectIndex(Func<IElement> element, int optionIndex)
        {
            this.Act(() =>
            {
                var unwrappedElement = element() as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();
                selectElement.SelectByIndex(optionIndex);
            });
        }
        public void MultiSelectText(Func<IElement> element, string[] optionTextCollection)
        {
            this.Act(() =>
            {
                var unwrappedElement = element() as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();

                foreach (var optionText in optionTextCollection)
                {
                    selectElement.SelectByText(optionText);
                }
            });
        }
 public void DeselectAll()
 {
     SelectElement element = new SelectElement(aWebElement);
     element.DeselectAll();
 }
        public void SelectIndex(ElementProxy element, int optionIndex)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();
                selectElement.SelectByIndex(optionIndex);
            });
        }
        public void MultiSelectText(ElementProxy element, string[] optionTextCollection)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();

                foreach (var optionText in optionTextCollection)
                {
                    selectElement.SelectByText(optionText);
                }
            });
        }
        public void MultiSelectIndex(ElementProxy element, int[] optionIndices)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();

                foreach (var optionIndex in optionIndices)
                {
                    selectElement.SelectByIndex(optionIndex);
                }
            });
        }
Beispiel #13
0
        public void _07_Multyselection_Box_List_Test()
        {

            //идем на сайт 
            driver.Url= "http://toolsqa.com/automation-practice-form/";

            //Находим список c выбором по имени и присваеваем его в oSelect
            SelectElement oSelect = new SelectElement(driver.FindElement(By.Name("selenium_commands")));

            //выбираем первый элемет, 2-х секундная пауза
            oSelect.SelectByIndex(0);
            System.Threading.Thread.Sleep(2000);
            
            //отменяем выбор, 2-х секундная пауза
            oSelect.DeselectByIndex(0); 
            System.Threading.Thread.Sleep(2000);

            //выбираем по содежанию, 2-х секундная пауза
            oSelect.SelectByText("Navigation Commands");
            System.Threading.Thread.Sleep(2000);

            //отменяем выбор, 2-х секундная пауза
            oSelect.DeselectByText("Navigation Commands");
            System.Threading.Thread.Sleep(2000);

            //создаем колекцию всех опций списка
            IList<IWebElement> Options = oSelect.Options;

            //для каждого вебэлемента в колеции
            foreach (IWebElement item in Options)
            {
                //выводим его текст
                Console.WriteLine(item.Text);

                //Выбираем его и 1 сек. пауза
                item.Click();
                System.Threading.Thread.Sleep(1000);

            }

            //отменяем выбор всех опций 2 сек. пауза
            oSelect.DeselectAll();
            System.Threading.Thread.Sleep(2000);
        }
Beispiel #14
0
 /// <summary>
 ///     Wraps Selenium's method. Unselects all options in the element
 /// </summary>
 /// <param name="element">Element from which to deselect all options</param>
 public void deselectAll(Tuple<locatorType, string> element)
 {
     //Grab the select element
     try
     {
         innerSelect = new SelectElement(findElement(element));
     }
     catch (UnexpectedTagNameException utne)
     {
         TestReporter.log("The element defined by locatoryType ["
             + element.Item1.ToString() + "] and identifier ["
             + element.Item2 + "] is not a select-type element.\n\n"
             + utne.StackTrace);
     }
     //Deselect all options
     innerSelect.DeselectAll();
 }
Beispiel #15
0
        /// <summary>
        /// Метод сбрасывается значение в элемент типа Select. Причём снимает ВСЕ значения даже если хоть одно должно быть.
        /// </summary>
        /// <param name="checkErrors">Проверка на ошибки</param>
        public void DeselectItems(bool checkErrors = true)
        {
            var selectElement = new SelectElement(BitrixFramework.FindWebElement(this));
            selectElement.DeselectAll();
            Log.MesNormal(String.Format("'{0}' -> сбошены сзначения", description));

            //проверяем страницу на наличие ошибок
            if (checkErrors)
            {
                BitrixFramework.CheckJSErrors();
                GM.CheckContentOnErrors();
            }
        }
Beispiel #16
0
        /// <summary>
        /// Method to select specified item from list.
        /// </summary>
        public void SelectItem(string[] itemList, bool selectMultiple = false)
        {
            string availbleItemsInList = string.Empty;
            string expectedItems = string.Empty;

            try
            {
                string firstItem = itemList.First();
                expectedItems = itemList.Aggregate(expectedItems, (current, item) => current + string.Format("\t" + item));
                _testObject = WaitAndGetElement();
                if (_testObject != null)
                    availbleItemsInList = _testObject.Text;

                #region  KRYPTON0156: Handling conditions where selectItem can be used for radio groups
                if (_testObject != null && (_testObject.GetAttribute("type") != null && _testObject.GetAttribute("type").ToLower().Equals("radio")))
                {
                    string radioValue = string.Empty;

                    //Check if given option is also stored in mapping column
                    string valueFromMapping = string.Empty;

                    foreach (KeyValuePair<string, string> mappingKey in _dicMapping)
                    {
                        if (mappingKey.Key.ToLower().Equals(firstItem.ToLower()))
                        {
                            valueFromMapping = mappingKey.Value;
                            break;
                        }
                    }

                    foreach (IWebElement radioObject in _testObjects)
                    {
                        //Retrieve value property of radio button and compare with passed text
                        string tempRadioValue = radioObject.GetAttribute("value");

                        if (tempRadioValue.ToLower().Equals(firstItem.ToLower()) || tempRadioValue.ToLower().Equals(valueFromMapping.ToLower()))
                        {
                            radioValue = tempRadioValue;
                            _testObject = radioObject;
                            break;
                        }
                    }

                    //Determine if a radio option was found or not, and take action based on that
                    if (!radioValue.Equals(string.Empty))
                    {
                        ExecuteScript(_testObject, "arguments[0].click();");
                        return;
                    }
                    Property.Remarks = string.Empty;
                    throw new Exception(Utility.GetCommonMsgVariable("KRYPTONERRCODE0022").Replace("{MSG}", firstItem));
                }
                #endregion

                // Entire section commented above works just fine, but damn slow on IE
                //Following code section is a shortcut for the same, and works reliably and fast on all browsers

                //Clear previus selection if multiple options needs to be selected

                if (selectMultiple)
                {
                    SelectElement select = new SelectElement(_testObject);
                    select.DeselectAll();
                }
                bool isSelectionSuccessful = false;
                foreach (string optionForSelection in itemList)
                {
                    string optionText = optionForSelection.Trim();

                    if (_testObject != null)
                    {
                        IList<IWebElement> allOptions = _testObject.FindElements(By.TagName("option"));
                        foreach (IWebElement option in allOptions)
                        {
                            try
                            {
                                string propertyValue = option.GetAttribute("value");
                                if (option.Displayed)
                                {
                                    if (option.Text.Contains(optionText))
                                    {
                                        isSelectionSuccessful = true;
                                        option.Click();
                                        break;
                                    }
                                    if (propertyValue != null && propertyValue.ToLower().Contains(optionText))
                                    {
                                        isSelectionSuccessful = true;
                                        option.Click();
                                        break;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                if (ex is StaleElementReferenceException)
                                {
                                    Thread.Sleep(2500);
                                    isSelectionSuccessful = true;
                                    option.Click();
                                    break;
                                }
                                throw new Exception(string.Format("Could not select \"{0}\" in the list with options:\" {1} \". Actual error:{2}", optionText, availbleItemsInList, ex.Message));
                            }
                        }
                    }
                }
                if (!isSelectionSuccessful)
                {
                    throw new Exception(string.Format("Could not found \"{0}\" in the list with options:\" {1} \".", expectedItems, availbleItemsInList));

                }
            }
            catch
            {
                throw new Exception(string.Format("Could not select \"{0}\" in the list with options:\" {1} \".", expectedItems, availbleItemsInList));

            }
        }
        public void SelectValue(ElementProxy element, string optionValue)
        {
            this.Act(CommandType.Action, () =>
            {
                var unwrappedElement = element.Element as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();
                selectElement.SelectByValue(optionValue);
            });
        }
        public void MultiSelectIndex(Func<IElement> element, int[] optionIndices)
        {
            this.Act(() =>
            {
                var unwrappedElement = element() as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();

                foreach (var optionIndex in optionIndices)
                {
                    selectElement.SelectByIndex(optionIndex);
                }
            });
        }
 public void DeselectAll()
 {
     BaseElement.Initialize();
     var x = new SelectElement(BaseElement.webElement);
     x.DeselectAll();
 }
        public void MultiSelectValue(Func<IElement> element, string[] optionValues)
        {
            this.Act(() =>
            {
                var unwrappedElement = element() as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();

                foreach (var optionValue in optionValues)
                {
                    selectElement.SelectByValue(optionValue);
                }
            });
        }
        /// <summary>
        /// select-multipleの選択と解除
        /// </summary>
        /// <param name="driver"></param>
        private static void EditMultiSelectField(IWebDriver driver)
        {
            // <select multiple="multiple">の選択
            var element = driver.FindElement(By.Id("id_selected_multiple"));
            var selectElement = new SelectElement(element);

            // 全部を選択
            selectElement.SelectByValue("1");
            selectElement.SelectByValue("2");
            selectElement.SelectByValue("3");

            // 一部を解除
            // 選択と同様、Index, Value, Textの3種類あり
            selectElement.DeselectByValue("2");

            // もしくは、一括で解除
            selectElement.DeselectAll();

            // 再度選択しておく
            selectElement.SelectByValue("2");
        }
        public void SelectValue(Func<IElement> element, string optionValue)
        {
            this.Act(() =>
            {
                var unwrappedElement = element() as Element;

                SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
                if (selectElement.IsMultiple) selectElement.DeselectAll();
                selectElement.SelectByValue(optionValue);
            });
        }
 public void ShouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelections()
 {
     IWebElement element = driver.FindElement(By.Name("selectomatic"));
     SelectElement elementWrapper = new SelectElement(element);
     Assert.Throws<InvalidOperationException>(() => elementWrapper.DeselectAll());
 }