当前位置: 首页>>代码示例>>C#>>正文


C# SelectElement.SelectByText方法代码示例

本文整理汇总了C#中OpenQA.Selenium.Support.UI.SelectElement.SelectByText方法的典型用法代码示例。如果您正苦于以下问题:C# SelectElement.SelectByText方法的具体用法?C# SelectElement.SelectByText怎么用?C# SelectElement.SelectByText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenQA.Selenium.Support.UI.SelectElement的用法示例。


在下文中一共展示了SelectElement.SelectByText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        protected override void Execute(IWebDriver driver, IWebElement element, CommandDesc command)
        {
            var selectElement = new SelectElement(element);

            var lowerCommand = command.Parameter.ToLower();
            if (lowerCommand.StartsWith("label="))
            {
                selectElement.SelectByText(command.Parameter.Substring(6));
                return;
            }

            if (lowerCommand.StartsWith("value="))
            {
                selectElement.SelectByValue(command.Parameter.Substring(6));
                return;
            }

            if (lowerCommand.StartsWith("index="))
            {
                selectElement.SelectByIndex(int.Parse(command.Parameter.Substring(6)));
                return;
            }

            selectElement.SelectByText(command.Parameter);
        }
开发者ID:equilobe,项目名称:SeleneseTestRunner,代码行数:25,代码来源:Select.cs

示例2: OneHundredRecordsOnPage

        public static void OneHundredRecordsOnPage()
        {
            var domainesDropdown = Driver.Instance.FindElement(By.Name("domain-datatables_length"));
            var selectNumberOfDomaines = new SelectElement(domainesDropdown);

            selectNumberOfDomaines.SelectByText("100");
        }
开发者ID:victorTomaCiprian,项目名称:Automation-Framework,代码行数:7,代码来源:DelivrabilityPage.cs

示例3: SelectEdamCheese

        /// <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();
            }
        }
开发者ID:BobLokerse,项目名称:SeleniumCoding,代码行数:35,代码来源:CheeseSelector.cs

示例4: AddProject

        public void AddProject()
        {
            BaseTest.BaseUrl = BugTrackerPage.HomePageUrl;
            BaseTest.Setup(BaseTest.BaseUrl);

            WebDriverWait wait = new WebDriverWait(BaseTest.BaseDriver, TimeSpan.FromSeconds(5));
            wait.Until((d) => { return d.Title.StartsWith("BugTracker"); });

            BugTrackerPage.AreAllElementShown();

            Assert.AreEqual("BugTracker.NET - bugs", BaseTest.BaseDriver.Title);
            // add new bug
            BugTrackerPage.AddNewBugBtn.Click();

            wait.Until((d) => { return d.Title.StartsWith("BugTracker.NET - Create Bug"); });

            try
            {
                Assert.AreEqual("Project:", BugTrackerPage.ProjectTextLabel.Text);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Assert.IsTrue(BugTrackerPage.ProjectSelect.Displayed);
            var select = new SelectElement(BugTrackerPage.ProjectSelect);
            select.SelectByText("HasCustomFieldsProject");
            //BaseTest.BaseDriver.FindElement(By.XPath("//option[@value='3']")).Click();
            Assert.AreEqual("Project-specific", BugTrackerPage.ProjectSpecificLabel.Text);
            Assert.IsTrue(BugTrackerPage.ProjectSpecificSelect.Displayed);

            BaseTest.TearDown();
        }
开发者ID:ekostadinov,项目名称:MyProjects,代码行数:34,代码来源:AddBugProjectSpecific.cs

示例5: Yeah

        public void Yeah()
        {
            using (var page = OpenPage(@"http://www.hemnet.se/"))
            {
                page.FindElement(By.Id("search_item_types_tomt")).Click();
                page.FindElement(By.Id("search_item_types_villa")).Click();
                page.FindElement(By.Id("search_item_types_fritidshus")).Click();

                // We must do the selection before interacting with the list, otherwise we will get an error
                var countyList = page.FindElement(By.Id("search_municipality"));
                var countyLabel = countyList.FindElement(By.XPath("//label[contains(.,'Håbo kommun')]"));
                var countyInput = countyLabel.FindElement(By.TagName("input"));

                countyList.Click(); // We must make the "option" visible before clicking on it, otherwise it will fail
                countyInput.Click(); // Selecting the option

                page.FindElementById("search_submit").Submit();

                var sortByList = new SelectElement(page.FindElement(By.Id("search-results-sort-by")));
                sortByList.SelectByText("Inkommet");

                var sortOrderList = new SelectElement(page.FindElement(By.Id("search-results-sort-order")));
                sortOrderList.SelectByText("Nyast först");

                Assert.That("yeah", Is.EqualTo("yeah"));
            }
        }
开发者ID:archive,项目名称:sandbox,代码行数:27,代码来源:HemnetSpecs.cs

示例6: TestHtml5CanvasDrawing

        public void TestHtml5CanvasDrawing()
        {
            try
            {
                driver.Navigate().GoToUrl("http://dl.dropbox.com/u/55228056/html5canvasdraw.html");

                //Get the HTML5 Canvas Element
                IWebElement canvas = driver.FindElement(By.Id("imageTemp"));
                //Select the Pencil Tool
                SelectElement drawtool = new SelectElement(driver.FindElement(By.Id("dtool")));
                drawtool.SelectByText("Pencil");

                //Create a Action Chain for Draw a shape on Canvas
                Actions builder = new Actions(driver);
                builder.ClickAndHold(canvas).MoveByOffset(10, 50).
                                             MoveByOffset(50, 10).
                                             MoveByOffset(-10, -50).
                                             MoveByOffset(-50, -10).Release().Perform();

                //Get a screenshot of Canvas element after Drawing and compare it to the base version
                Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
                string screenshot = ss.AsBase64EncodedString;
                byte[] screenshotAsByteArray = ss.AsByteArray;
                ss.SaveAsFile(@"c:\tmp\post.png", ImageFormat.Png);
            }
            catch (Exception e)
            {
                Assert.Fail("Test Failed due to exception '" + e.Message + "'");
            }
        }
开发者ID:oluk68,项目名称:SELENIUM2,代码行数:30,代码来源:Html5CanvasDrawing.cs

示例7: SelectByText

		public void SelectByText(string text)
		{
			IWebElement webElement =  _pageElement.WebDriver.WaitForElement(_pageElement.By);

			SelectElement selectElement = new SelectElement(webElement);
			selectElement.SelectByText(text);
		}
开发者ID:florianwittmann,项目名称:regtesting,代码行数:7,代码来源:DefaultSelectBehaviour.cs

示例8: LeagueTable

    public void LeagueTable()
    {
        //string team = "Nottm Forest";
            FindSport();
            IWebElement football = _driver.FindElement(By.LinkText("Football"));
            football.Click();
            IWebElement tables = _driver.FindElement(By.LinkText("Tables"));
            tables.Click();
            SelectElement dropdown = new SelectElement(_driver.FindElement(By.Id("uk-group-drop-down")));
            IList<IWebElement> dropdownOptions = dropdown.Options;
            dropdown.SelectByText("Championship");
            IWebElement updateTable = _driver.FindElement(By.Id("filter-nav-submit"));
            updateTable.Click();
            IWebElement userTeam = _driver.FindElement(By.Name("Nottm Forest"));
            userTeam.Click();

            foreach (IWebElement dropDownOption in dropdownOptions)
            {
                List<string> optionsText = new List<string>();
                Console.WriteLine(dropDownOption.Text);
                optionsText.Add(dropDownOption.Text);
                //if (dropDownOption.Text == " Championship ")
                //{
                //    Assert.AreEqual(dropDownOption.Text, (" Championship "));
                //}
            }
    }
开发者ID:bizfitechtestteam,项目名称:jack-dev-area,代码行数:27,代码来源:JackTest.cs

示例9: SelectCurrency

        public MessageAndAmount SelectCurrency(string currencyCode)
        {
            var currencyCodeSelect = new SelectElement(_currencyCodeDropdown);
            currencyCodeSelect.SelectByText(currencyCode);

            return this;
        }
开发者ID:sonofelaine,项目名称:just-giving-code-test,代码行数:7,代码来源:MessageAndAmount.cs

示例10: TestDropdown

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

             		    //Verify Dropdown does not support multiple selection
             		    Assert.IsFalse(make.IsMultiple);
             		    //Verify Dropdown has four options for selection
            Assert.AreEqual(4, make.Options.Count);

            //We will verify Dropdown has expected values as listed in a array
            ArrayList exp_options = new ArrayList(new String [] {"BMW", "Mercedes", "Audi","Honda"});
            var act_options = new ArrayList();

            //Retrieve the option values from Dropdown using getOptions() method
            foreach(IWebElement option in make.Options)
                 act_options.Add(option.Text);

            //Verify expected options array and actual options array match
            Assert.AreEqual(exp_options.ToArray(),act_options.ToArray());

            //With Select class we can select an option in Dropdown using Visible Text
            make.SelectByText("Honda");
            Assert.AreEqual("Honda", make.SelectedOption.Text);

            //or we can select an option in Dropdown using value attribute
            make.SelectByValue("audi");
            Assert.AreEqual("Audi", make.SelectedOption.Text);

            //or we can select an option in Dropdown using index
            make.SelectByIndex(0);
            Assert.AreEqual("BMW", make.SelectedOption.Text);
        }
开发者ID:vikramuk,项目名称:Selenium,代码行数:33,代码来源:SelectTests.cs

示例11: FillInControlsAsFollows

 public void FillInControlsAsFollows(Table table)
 {
     foreach (var row in table.Rows)
     {
         var element = BrowserDriver.FindElement(By.Name(row[0]));
         var elementType = element.GetAttribute("type");
         if (elementType == "text" || elementType == "password")
         {
             element.Clear();
             element.SendKeys(row[1]);
         }
         if (elementType == "select-one")
         {
             var selectElement = new SelectElement(element);
             selectElement.SelectByText(row[1]);
         }
         if (elementType == "checkbox")
         {
             var needToBeChecked = Convert.ToBoolean(row[1]);
             if ((element.Selected && !needToBeChecked) || (!element.Selected && needToBeChecked))
             {
                 element.Click();
             }
         }
     }
 }
开发者ID:lAnubisl,项目名称:WebApplicationsDevelopmentLessons,代码行数:26,代码来源:Steps.cs

示例12: FormTest

        public void FormTest()
        {
            //initialization: navigate to site, find dropdownlist and selection elements
            driver.Navigate().GoToUrl("http://www.travelocity.com/");
            driver.FindElement(By.Id("primary-header-flight")).Click();
            driver.FindElement(By.Id("flight-type-one-way-label")).Click();
            driver.FindElement(By.Id("flight-origin")).SendKeys("Fuzhou, China (FOC-Changle Intl.)");
            driver.FindElement(By.Id("flight-destination")).SendKeys("Greensboro, NC, United States (GSO-All Airports)");
            driver.FindElement(By.Id("flight-departing")).SendKeys("07/06/2015");
            IWebElement dropdown = driver.FindElement(By.Id("flight-adults"));
            SelectElement select = new SelectElement(dropdown);
            select.SelectByValue("2");
            driver.FindElement(By.Id("advanced-flight-refundable")).Click();
            IWebElement preferred_airline = driver.FindElement(By.Id("flight-advanced-preferred-airline"));
            SelectElement select_airline = new SelectElement(preferred_airline);
            select_airline.SelectByText("Air China");
            driver.FindElement(By.Id("search-button")).Click();

            if(driver.FindElement(By.Id("captchaBox")) !=  null)
            {
                driver.Navigate().Back();
            }

            Thread.Sleep(6000);
            driver.Dispose();
        }
开发者ID:qzhang1,项目名称:SeleniumUnitTestTest,代码行数:26,代码来源:UnitTest1.cs

示例13: ShouldAllowOptionsToBeSelectedByVisibleText

 public void ShouldAllowOptionsToBeSelectedByVisibleText()
 {
     IWebElement element = driver.FindElement(By.Name("select_empty_multiple"));
     SelectElement elementWrapper = new SelectElement(element);
     elementWrapper.SelectByText("select_2");
     IWebElement firstSelected = elementWrapper.AllSelectedOptions[0];
     Assert.AreEqual("select_2", firstSelected.Text);
 }
开发者ID:lesmana,项目名称:selenium,代码行数:8,代码来源:SelectBrowserTests.cs

示例14: select_menu_item

 private void select_menu_item(int listNum, string item)
 {
     selectionList =
                     browser.FindElement(
                         By.Id("ctl00_SampleContent_DropDownList" + listNum));
     var optionsList = new SelectElement(selectionList);
     optionsList.SelectByText(item);
 }
开发者ID:jimholmes,项目名称:PresentationDemos,代码行数:8,代码来源:v4_selects_to_separate_method.cs

示例15: select_option

 private void select_option(int listNum, string option)
 {
     var selectionList =
         browser.FindElement(
             By.Id("ctl00_SampleContent_DropDownList" + listNum));
     var optionsList = new SelectElement(selectionList);
     optionsList.SelectByText(option);
 }
开发者ID:GrillerGeek,项目名称:SE13,代码行数:8,代码来源:Step3_working_with_cascading_menus.cs


注:本文中的OpenQA.Selenium.Support.UI.SelectElement.SelectByText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。