Пример #1
0
        public void SetSelectedOptionByValue(string value, bool clearMultiselect = true)
        {
            var selectElement = new SelectElement(element);

            if (clearMultiselect && selectElement.IsMultiple)
            {
                selectElement.DeselectAll();
            }
            selectElement.SelectByValue(value);
        }
        public void UserRegistrationOptionalFields()
        {
            SelectElement SelectUserRole = new SelectElement(driver.FindElement(By.CssSelector(UserConstants.UserRole)));

            SelectUserRole.DeselectAll();
            SelectUserRole.SelectByValue(UserConstants.SelectValue);

            driver.FindElement(By.CssSelector(UserConstants.GrantApprovalRights)).Click();

            driver.FindElement(By.CssSelector(UserConstants.GrandSuperAdminPrivileges)).Click();
        }
Пример #3
0
        public static void SetAdvancedFilter([NotNull] IWebDriver driver, int releaseYearFrom = -1, int releaseYearTo = -1, int metacriticFrom = -1, int metaCriticTo = -1, ICollection <string> genres = null)
        {
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            DialogHelper.TestDialog(driver, SiteConstants.AdvancedFilterAnchorId, SiteConstants.AdvancedFilterModalId, () =>
            {
                if (releaseYearFrom >= 0)
                {
                    Console.WriteLine(Invariant($"Setting advanced filter to releaseYearFrom: {releaseYearFrom}"));
                    driver.SelectValue(By.Id(SiteConstants.AdvancedFilterReleaseYearFromOptionsId), releaseYearFrom.ToString(CultureInfo.InvariantCulture));
                }

                if (releaseYearTo >= 0)
                {
                    Console.WriteLine(Invariant($"Setting advanced filter to releaseYearTo: { releaseYearTo}"));
                    driver.SelectValue(By.Id(SiteConstants.AdvancedFilterReleaseYearToOptionsId), releaseYearTo.ToString(CultureInfo.InvariantCulture));
                }

                if (metacriticFrom >= 0)
                {
                    Console.WriteLine(Invariant($"Setting advanced filter to metacriticFrom: { metacriticFrom}"));
                    driver.SelectValue(By.Id(SiteConstants.AdvancedFilterMetacriticFromOptionsId), metacriticFrom.ToString(CultureInfo.InvariantCulture));
                }

                if (metaCriticTo >= 0)
                {
                    Console.WriteLine(Invariant($"Setting advanced filter to metaCriticTo: { metaCriticTo}"));
                    driver.SelectValue(By.Id(SiteConstants.AdvancedFilterMetacriticToOptionsId), metaCriticTo.ToString(CultureInfo.InvariantCulture));
                }

                if (genres != null)
                {
                    Console.WriteLine(Invariant($"Setting advanced filter to genres: {genres.StringJoin()}"));
                    var genreSelect = new SelectElement(driver.FindElement(By.Id(SiteConstants.AdvancedFilterGenreOptionsId)));

                    genreSelect.DeselectAll();
                    Assert.IsTrue(driver.FindElement(By.Id(SiteConstants.AdvancedFilterNoGenresSelectedSpanId)).Displayed,
                                  "Expected no genre selected notification to be visible when no genres are selected");
                    Assert.IsFalse(driver.FindElement(By.Id(SiteConstants.AdvancedFilterApplyButtonId)).Enabled,
                                   "Expected advanced filter apply button to be disabled when no genres are selected");

                    foreach (var genre in genres)
                    {
                        genreSelect.SelectByValue(genre);
                    }
                }

                driver.FindElement(By.Id(SiteConstants.AdvancedFilterApplyButtonId)).Click();
            });
        }
Пример #4
0
        public void MultipleTest()
        {
            // Create a new instance of the Firefox driver
            IWebDriver driver = new ChromeDriver("D:\\SagarAutomation");

            //driver.Manage().Window.Maximize();
            // Launch the URL
            driver.Url = "http://toolsqa.com/automation-practice-form";

            driver.FindElement(By.Id("cookie_action_close_header")).Click();

            // Put an Implicit wait, this means that any search for elements on the page could take the time the implicit wait is set for before throwing exception
            //  driver.Manage().Timeouts().ImplicitWait(TimeSpan.FromSeconds(10));

            // Launch the URL
            //  driver.Url = "http://toolsqa.com/automation-practice-form";
            // Step 3: Select 'Selenium Commands' Multiple select box ( Use Name locator to identify the element )
            SelectElement oSelection = new SelectElement(driver.FindElement(By.Name("selenium_commands")));

            // Step 4: Select option 'Browser Commands'  and then deselect it (Use selectByIndex and deselectByIndex)
            oSelection.SelectByIndex(0);
            Thread.Sleep(2000);
            oSelection.DeselectByIndex(0);

            // Step 5: Select option 'Navigation Commands'  and then deselect it (Use selectByVisibleText and deselectByVisibleText)
            oSelection.SelectByText("Navigation Commands");
            Thread.Sleep(2000);

            oSelection.DeselectByText("Navigation Commands");

            // Step 6: Print and select all the options for the selected Multiple selection list.
            IList <IWebElement> oSize = oSelection.Options;
            int iListSize             = oSize.Count;

            // Setting up the loop to print all the options
            for (int i = 0; i < iListSize; i++)
            {
                // Storing the value of the option
                String sValue = oSelection.Options.ElementAt(i).Text;
                // Printing the stored value
                Console.WriteLine("Value of the Item is :" + sValue);
                // Selecting all the elements one by one
                oSelection.SelectByIndex(i);

                Thread.Sleep(2000);
            }

            // Step 7: Deselect all
            oSelection.DeselectAll();

            // Kill the browser
            driver.Close();
        }
Пример #5
0
 /// <summary>
 /// Deselects all the currently selected values from the given element.
 /// </summary>
 /// <param name="selectElement"></param>
 public void DeselectAll(By selectElement)
 {
     try
     {
         var select = new SelectElement(driver.FindElement(selectElement));
         select.DeselectAll();
     }
     catch (Exception e)
     {
         MyLogger.Log.Error($"Failed to de-select all selected options from select element: {selectElement}. {e.Message}");
         throw e;
     }
 }
Пример #6
0
        public void SetIndex_Combobox_IdEndsWith(string prefixIdSignature, int index)
        {
            SelectElement targetElement = GetEle_Combobox_IdEndsWith(prefixIdSignature);

            if (index < 0)
            {
                targetElement.DeselectAll();
            }
            else
            {
                targetElement.SelectByIndex(index);
            }
        }
Пример #7
0
        public void SetText_Combobox_IdEndsWith(string prefixIdSignature, string text)
        {
            SelectElement targetElement = GetEle_Combobox_IdEndsWith(prefixIdSignature);

            if (text == null)
            {
                targetElement.DeselectAll();
            }
            else
            {
                targetElement.SelectByText(text);
            }
        }
Пример #8
0
        public void SetValue_Combobox_IdEndsWith(string prefixIdSignature, string value)
        {
            SelectElement targetElement = GetEle_Combobox_IdEndsWith(prefixIdSignature);

            if (value == null)
            {
                targetElement.DeselectAll();
            }
            else
            {
                targetElement.SelectByValue(value);
            }
        }
Пример #9
0
        public void SelectElement_Dropdown()
        {
            IWebDriver driver = new ChromeDriver();

            driver.Navigate().GoToUrl(@"http://www.google.com");

            SelectElement select = new SelectElement(driver.FindElement(By.TagName("select")));

            select.DeselectAll();
            select.SelectByText("Edam");
            select.SelectByIndex(1);
            select.SelectedOption.GetAttribute("country");
        }
        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 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);
            });
        }
Пример #12
0
        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);
            });
        }
Пример #13
0
        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);
            });
        }
        private void SelectAsync(IReadOnlyList <IDomElement> elements, Action <SelectElement> action)
        {
            var nativeElements = GetWebDriverElementsFromDomElements(elements);

            foreach (var nativeElement in nativeElements)
            {
                var selectElement = new SelectElement(nativeElement);
                if (selectElement.IsMultiple)
                {
                    selectElement.DeselectAll();
                }

                action(selectElement);
            }
        }
Пример #15
0
            /// <summary>
            /// Deselect all items
            /// </summary>
            public bool All()
            {
                try
                {
                    SelectElement select = new SelectElement(this.element);
                    select.DeselectAll();
                    return(true);
                }
                catch (Exception)
                {
                    //// Need to do nothing
                }

                return(false);
            }
Пример #16
0
        public void SelectDropdownValue()
        {
            IWebElement   dropdown = driver.FindElement(By.Id("countriesMultiple"));
            SelectElement element  = new SelectElement(dropdown);

            element.SelectByText("India");

            Thread.Sleep(2000);

            element.SelectByIndex(1);
            Thread.Sleep(2000);

            element.DeselectAll();
            Thread.Sleep(2000);
        }
Пример #17
0
        /// <summary>
        /// Clear all selected entries from a list box. Supported onlywhen the select element supports multiple selection.
        /// </summary>
        /// <param name="selectLocator">The select locator.</param>
        /// <param name="type">Type of locator.</param>
        public void DeselectAll(string selectLocator, FindType type)
        {
            // Deselect all only if there are items in the control
            if (GetListItems(selectLocator, type).Count() != 0)
            {
                SelectElement select = FindSelectElement(selectLocator, type);

                if (null != select)
                {
                    select.DeselectAll();

                    // wait for specified time before returning the control back
                    Thread.Sleep(ElementOperationDelay);
                }
            }
        }
        public void SelectFromDropDow()
        {
            var dropDown          = new SelectElement(element);
            var allSelectedOption = dropDown.AllSelectedOptions;
            var selectedOption    = dropDown.SelectedOption;
            var isMultiple        = dropDown.IsMultiple;
            var listOfAllOption   = dropDown.Options;
            var wrappedElement    = dropDown.WrappedElement;

            dropDown.DeselectAll();
            dropDown.DeselectByIndex(50);
            dropDown.DeselectByText("roma");
            dropDown.DeselectByValue("12345");
            dropDown.SelectByIndex(60);
            dropDown.SelectByText("Roma");
            dropDown.SelectByValue("hgfdsa");
        }
Пример #19
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();
 }
Пример #20
0
        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);
                }
            });
        }
Пример #21
0
        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);
                }
            });
        }
        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 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);
                }
            });
        }
Пример #24
0
        public void SetValue(IWebElement webElement, string value)
        {
            var select = new SelectElement(webElement);

            if (select.IsMultiple)
            {
                select.DeselectAll();
                var values = value.Split(MulipleValueSeparator);
                foreach (var singleValue in values)
                {
                    select.SelectByText(singleValue);
                }
            }
            else
            {
                select.SelectByText(value);
            }
        }
Пример #25
0
        public void MultiSelect()
        {
            // Open automation practice form
            driver.Navigate().GoToUrl("http://toolsqa.com/automation-practice-form/");

            // Select 'Selenium Commands' Mulitplie selection box (Use Name locator to identify the element)
            SelectElement seleniumCommandsOptions = new SelectElement(driver.FindElement(By.Name("selenium_commands")));

            // Select option 'Browser Commands' and then deselect it (Use SelectByIndex and DeselectByIndex)
            seleniumCommandsOptions.SelectByIndex(0);
            Thread.Sleep(1000);
            seleniumCommandsOptions.DeselectByIndex(0);

            // Select option 'Navigation Commands' and then deselect it (Use SelectByText and DeselectByText)
            seleniumCommandsOptions.SelectByText("Navigation Commands");
            Thread.Sleep(1000);
            seleniumCommandsOptions.DeselectByText("Navigation Commands");

            // Print and select all the options for the selected Mulitple selection list.
            IList <IWebElement> seleniumCommandsOptionsSize = seleniumCommandsOptions.Options;
            int iListSeleniumCommandsOptionsSize            = seleniumCommandsOptionsSize.Count;

            for (int i = 0; i < iListSeleniumCommandsOptionsSize; i++)
            {
                // Storing the value of the option
                String sValue = seleniumCommandsOptions.Options.ElementAt(i).Text;

                // Printing the stored value
                Console.WriteLine(sValue);

                // Selecting all the elements one by one
                seleniumCommandsOptions.SelectByIndex(i);

                Thread.Sleep(2000);
            }

            // Deselect all options
            seleniumCommandsOptions.DeselectAll();
            Thread.Sleep(2000);

            // Close the browser
            driver.Quit();
        }
Пример #26
0
        public void Set(IModelFieldValue value)
        {
            if (!_select.IsMultiple)
            {
                _select.SelectByValue(value.Value);
                return;
            }

            _select.DeselectAll();
            if (value.HasMultipleValues)
            {
                foreach (var selectedValue in value.Values)
                {
                    _select.SelectByValue(selectedValue);
                }
            }
            else
            {
                _select.SelectByValue(value.Value);
            }
        }
Пример #27
0
        /// <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");
        }
Пример #28
0
        public void Set(object value, IWebElement element, IWebDriver driver)
        {
            if (element == null)
            {
                throw new ArgumentNullException(nameof(element));
            }
            if (driver == null)
            {
                throw new ArgumentNullException(nameof(driver));
            }

            var select = new SelectElement(element);

            if (value == null)
            {
                select.DeselectAll();
            }
            else
            {
                select.SelectByText((string)Convert.ChangeType(value, typeof(string)));
            }
        }
Пример #29
0
        public void multiselectTest()
        {
            IWebDriver driver = new FirefoxDriver();

            driver.Url = "http://toolsqa.wpengine.com/automation-practice-form/";

            //make a new selectelement called sSelect at the multiselect box
            SelectElement sSelect = new SelectElement(driver.FindElement(By.Name("selenium_commands")));

            //select and then deselect something by index
            sSelect.SelectByIndex(0);
            Thread.Sleep(2000);
            sSelect.DeselectByIndex(0);
            Thread.Sleep(2000);

            //select and then deselect something else by text
            sSelect.SelectByText("Navigation Commands");
            Thread.Sleep(2000);
            sSelect.DeselectByText("Navigation Commands");
            Thread.Sleep(2000);

            //get options in multiselect into a list
            IList <IWebElement> sList = sSelect.Options;
            int sLength = sList.Count;

            //Print all the options in the multiselect
            for (int i = 0; i < sLength; i++)
            {
                String sValue = sList.ElementAt(i).Text;
                Console.WriteLine(sValue);

                //select all options
                sSelect.SelectByIndex(i);
            }
            sSelect.DeselectAll();
            Thread.Sleep(2000);

            driver.Close();
        }
        public void Exercise2()
        {
            //Get all option of Selenium commands multiple

            SelectElement selectOption = new SelectElement(driver.FindElement(By.Name("selenium_commands")));

            //Select option "Browser Commands" by index

            selectOption.SelectByIndex(0);

            Thread.Sleep(2000);

            //Deselect option "Browser Commands"

            selectOption.DeselectByIndex(0);

            //Select option "Navigation Commands"

            selectOption.SelectByIndex(1);

            Thread.Sleep(2000);

            //Deselect for option "Navigation Commands"

            selectOption.DeselectByIndex(1);

            //Print all options of selected multiple selection list

            for (int i = 0; i < selectOption.Options.Count; i++)
            {
                Console.WriteLine("The value of option at index " + i + " : " + selectOption.Options.ElementAt(i).Text);
            }


            //Deselect all options

            selectOption.DeselectAll();
        }