當前位置: 首頁>>代碼示例>>C#>>正文


C# SelectElement.DeselectByText方法代碼示例

本文整理匯總了C#中OpenQA.Selenium.Support.UI.SelectElement.DeselectByText方法的典型用法代碼示例。如果您正苦於以下問題:C# SelectElement.DeselectByText方法的具體用法?C# SelectElement.DeselectByText怎麽用?C# SelectElement.DeselectByText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenQA.Selenium.Support.UI.SelectElement的用法示例。


在下文中一共展示了SelectElement.DeselectByText方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestMultipleSelectList

        public void TestMultipleSelectList()
        {
            //Get the List as a Select using it's name attribute
             		    SelectElement color = new SelectElement(driver.FindElement(By.Name("color")));

             		    //Verify List support multiple selection
            Assert.IsTrue(color.IsMultiple);

            //Verify List has five options for selection
            Assert.AreEqual(5, color.Options.Count);

            //Select multiple options in the list using visible text
            color.SelectByText("Black");
            color.SelectByText("Red");
            color.SelectByText("Silver");

            //Verify there 3 options selected in the list
            Assert.AreEqual(3,color.AllSelectedOptions.Count);

            //We will verify list has multiple options selected as listed in a array
            var exp_sel_options = new ArrayList(new String[]{"Black", "Red", "Silver"});
            var act_sel_options = new ArrayList();

            foreach(IWebElement option in color.AllSelectedOptions)
                act_sel_options.Add(option.Text);

            //Verify expected array for selected options match with actual options selected
            Assert.AreEqual(exp_sel_options.ToArray(), act_sel_options.ToArray());

            //Deselect an option using visible text
            color.DeselectByText("Silver");
            //Verify selected options count
            Assert.AreEqual(2, color.AllSelectedOptions.Count);

            //Deselect an option using value attribute of the option
            color.DeselectByValue("rd");
            //Verify selected options count
            Assert.AreEqual(1, color.AllSelectedOptions.Count);

            //Deselect an option using index of the option
            color.DeselectByIndex(0);
            //Verify selected options count
            Assert.AreEqual(0, color.AllSelectedOptions.Count);
        }
開發者ID:vikramuk,項目名稱:Selenium,代碼行數:44,代碼來源:SelectTests.cs

示例2: DeselectByText

 public void DeselectByText(string text)
 {
     SelectElement element = new SelectElement(aWebElement);
     element.DeselectByText(text);
 }
開發者ID:geeksree,項目名稱:cSharpGeeks,代碼行數:5,代碼來源:SeleniumWebCombobox.cs

示例3: ShouldAllowUserToDeselectOptionsByVisibleText

        public void ShouldAllowUserToDeselectOptionsByVisibleText()
        {
            IWebElement element = driver.FindElement(By.Name("multi"));
            SelectElement elementWrapper = new SelectElement(element);
            elementWrapper.DeselectByText("Eggs");
            IList<IWebElement> returnedOptions = elementWrapper.AllSelectedOptions;

            Assert.AreEqual(1, returnedOptions.Count);
        }
開發者ID:JoeHe,項目名稱:selenium,代碼行數:9,代碼來源:SelectBrowserTests.cs

示例4: ShouldNotAllowUserToDeselectOptionsByInvisibleText

 public void ShouldNotAllowUserToDeselectOptionsByInvisibleText()
 {
     IWebElement element = driver.FindElement(By.Name("invisi_select"));
     SelectElement elementWrapper = new SelectElement(element);
     elementWrapper.DeselectByText("Apples");
 }
開發者ID:JoeHe,項目名稱:selenium,代碼行數:6,代碼來源:SelectBrowserTests.cs

示例5: ShouldNotAllowUserToDeselectOptionsByInvisibleText

 public void ShouldNotAllowUserToDeselectOptionsByInvisibleText()
 {
     IWebElement element = driver.FindElement(By.Name("invisi_select"));
     SelectElement elementWrapper = new SelectElement(element);
     Assert.Throws<NoSuchElementException>(() => elementWrapper.DeselectByText("Apples"));
 }
開發者ID:draculavlad,項目名稱:selenium,代碼行數:6,代碼來源:SelectBrowserTests.cs

示例6: _07_Multyselection_Box_List_Test

        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);
        }
開發者ID:raptorbox01,項目名稱:csharp_exercises,代碼行數:44,代碼來源:Driver.cs

示例7: deselectByVisibleText

 /// <summary>
 ///     Wraps Selenium's method. Deselects options from a selectable element
 /// </summary>
 /// <param name="element">Element from which to deselect options</param>
 /// <param name="text">Text to deselect</param>
 public void deselectByVisibleText(Tuple<locatorType, string> element, string text)
 {
     try
     {
         //Grab the SelectElement
         innerSelect = new SelectElement(findElement(element));
         //Deselect the option defined by the text
         innerSelect.DeselectByText(text);
     }
     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);
     }
 }
開發者ID:waitsavery,項目名稱:Selenium_CS,代碼行數:22,代碼來源:Element.cs

示例8: ShouldNotAllowUserToDeselectByTextWhenSelectDoesNotSupportMultipleSelections

 public void ShouldNotAllowUserToDeselectByTextWhenSelectDoesNotSupportMultipleSelections()
 {
     IWebElement element = driver.FindElement(By.Name("selectomatic"));
     SelectElement elementWrapper = new SelectElement(element);
     Assert.Throws<InvalidOperationException>(() => elementWrapper.DeselectByText("Four"));
 }
開發者ID:RanchoLi,項目名稱:selenium,代碼行數:6,代碼來源:SelectBrowserTests.cs

示例9: ShouldThrowExceptionOnDeselectByTextIfOptionDoesNotExist

 public void ShouldThrowExceptionOnDeselectByTextIfOptionDoesNotExist()
 {
     IWebElement element = driver.FindElement(By.Name("select_empty_multiple"));
     SelectElement elementWrapper = new SelectElement(element);
     Assert.Throws<NoSuchElementException>(() => elementWrapper.DeselectByText("not there"));
 }
開發者ID:RanchoLi,項目名稱:selenium,代碼行數:6,代碼來源:SelectBrowserTests.cs


注:本文中的OpenQA.Selenium.Support.UI.SelectElement.DeselectByText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。