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


C# UI.SelectElement类代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: GivenIHaveEnteredSomethingIntoTheSearch

        public void GivenIHaveEnteredSomethingIntoTheSearch(int zip, int category, int subCategory)
        {
            //Navigate to the site
            driver.Navigate().GoToUrl(WeNeedUHaveUrls.Home);
            // Find the text input element by its name
            IWebElement query = driver.FindElement(By.Name("ZipCode"));
            // Enter something to search for
            query.SendKeys(zip.ToString());
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(3000));
            wait.Until(x =>
            {
                try
                {
                    SelectElement selectElement = new SelectElement(driver.AjaxFind(By.Id("Category"), 3000));
                    return selectElement.Options.Count>1;
                }
                catch (StaleElementReferenceException)
                {
                    return false;
                }
            });
            IWebElement dropDownListBox = driver.FindElement(By.Id("Category"));
            
            SelectElement clickThis = new SelectElement(dropDownListBox);
            clickThis.SelectByIndex(category);

            IWebElement dropDownListBox2 = driver.FindElement(By.Id("SubCategory"));
            SelectElement clickThis2 = new SelectElement(dropDownListBox2);
            clickThis2.SelectByIndex(subCategory);

            // Now submit the form
            query.Submit();
        }
开发者ID:IanFelton,项目名称:WeNeedUHave,代码行数:33,代码来源:SearchGivens.cs

示例5: Type

 public AddFieldDialog Type(FieldType type)
 {
     var element = FindElement("field-type");
     var select = new SelectElement(element);
     select.SelectByValue(type.ToText());
     return this;
 }
开发者ID:backand,项目名称:SeleniumAutomation,代码行数:7,代码来源:AddFieldDialog.cs

示例6: 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

示例7: AssetSelection

        private static void AssetSelection(IWebDriver driver)
        {
            for (var n = 0; n <= 1; n++)
            {
                driver.FindElement(By.CssSelector("img.img-responsive.center-block")).Click();
                driver.FindElement(By.Id("s2id_autogen1")).Click();

                var groups = new SelectElement(driver.FindElement(By.Id("groups")));

                groups.SelectByIndex(n);
                var assetType = groups.SelectedOption.Text;

                driver.FindElement(By.CssSelector("button.btn.gradient")).Click(); //click search

                //Groups dropdown
                IList<IWebElement> details = driver.FindElements(By.LinkText("Details"));

                Console.WriteLine("There are {0} {1} ", details.Count(), assetType);

                NavigateGroups(driver, details);
                // driver.FindElement(By.CssSelector("img.img-responsive.center-block")).Click();

                // driver.FindElement(By.CssSelector("a.select2-search-choice-close")).Click(); //clear
            }
            //Console.ReadKey();
        }
开发者ID:ngaruko,项目名称:WebDriverDemo,代码行数:26,代码来源:Program.cs

示例8: 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

示例9: getElementValue

        public static string getElementValue(this IWebElement pElement, ElementType pElementType)
        {
            string result;
            switch (pElementType)
            {
                case ElementType.TextInput:
                    result = pElement.GetAttribute("value");
                    break;
                case ElementType.Ddl:
                    result = new SelectElement(pElement).SelectedOption.Text;
                    break;
                case ElementType.RadioBtn:
                    result = "";
                    break;
                case ElementType.Btn:
                    result = "";
                    break;
                case ElementType.CheckBox:
                    result = "";
                    break;
                default:
                    result = "";
                    break;
            }

            return result;
        }
开发者ID:s-endres,项目名称:TestCasesExample,代码行数:27,代码来源:SeleniumGetMethods.cs

示例10: SelectJobPosition

 public void SelectJobPosition(string job)
 {
     IWebElement jobPosition = driver.FindElement(By.Id("department-select"));
        MakeElementVisible(jobPosition);
        SelectElement selectJobPosition = new SelectElement(jobPosition);
        selectJobPosition.SelectByValue(job);
 }
开发者ID:MaryiaDounar,项目名称:EpamSite,代码行数:7,代码来源:CareersPage.cs

示例11: SelectLocation

 public void SelectLocation(string location)
 {
     IWebElement jobLocation = driver.FindElement(By.Id("location-select"));
        MakeElementVisible(jobLocation);
        SelectElement selectJobLocation = new SelectElement(jobLocation);
        selectJobLocation.SelectByValue(location);
 }
开发者ID:MaryiaDounar,项目名称:EpamSite,代码行数:7,代码来源:CareersPage.cs

示例12: 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

示例13: GetList

        //List<string> DajListe(string xpath) {
        //    IWebElement elem = PobierzElement(xpath);
        //    SelectElement selectList = new SelectElement(elem);
        //    IList<IWebElement> options = selectList.Options;
        //    List<string> list = new List<string>();
        //    foreach (IWebElement w in options) {
        //        list.Add(w.Text);
        //    }
        //    return list;
        //}
        public static IList<IWebElement> GetList(IWebElement elem)
        {
            SelectElement selectList = new SelectElement(elem);
            IList<IWebElement> options = selectList.Options;

            return options;
        }
开发者ID:maciejpitucha,项目名称:taryfy_cs,代码行数:17,代码来源:SeleniumUtils.cs

示例14: 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

示例15: FindSelectOptionByValue

        public static IWebElement FindSelectOptionByValue(SelectElement selectElement, string value)
        {
            var option = selectElement.Options
                .FirstOrDefault(x => x.GetAttribute("value") == value);

            return option;
        }
开发者ID:MichalGrzegorzak,项目名称:Ylvis,代码行数:7,代码来源:WebElementHelper.cs


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