예제 #1
0
 public void SelectLocation(string location)
 {
     IWebElement jobLocation = driver.FindElement(By.Id("location-select"));
        MakeElementVisible(jobLocation);
        SelectElement selectJobLocation = new SelectElement(jobLocation);
        selectJobLocation.SelectByValue(location);
 }
예제 #2
0
        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);
        }
        public void CopyIndicators()
        {
            var driver = Driver;
            new NavigateTo(driver).ProfilesAndIndicatorsPage();
            new WaitFor(driver).PageWithModalPopUpToLoad();

            // Select option in menu
            var profileSelect = driver.FindElement(By.Id("selectedProfile"));
            var selectElement = new SelectElement(profileSelect);
            selectElement.SelectByValue("diabetes");

            // Tick an indicator to copy
            var tickBox = driver.FindElements(By.Name("90690_selected"));
            tickBox.First().Click();

            // Click copy
            var copyButton = driver.FindElement(By.Id("copy-indicators-button"));
            copyButton.Click();
            SeleniumHelper.WaitForExpectedElementToBeVisible(driver, By.Id("copyIndicators"));

            // Check the correct profile is selected in the profile menu
            var copyProfileSelect = driver.FindElement(By.Id("selectedProfileId"));
            var copySelectElement = new SelectElement(copyProfileSelect);
            var selectedText = copySelectElement.SelectedOption.Text;
            Assert.AreEqual("Diabetes", selectedText);
        }
예제 #4
0
 public AddFieldDialog Type(FieldType type)
 {
     var element = FindElement("field-type");
     var select = new SelectElement(element);
     select.SelectByValue(type.ToText());
     return this;
 }
예제 #5
0
        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);
        }
예제 #6
0
 public void SelectJobPosition(string job)
 {
     IWebElement jobPosition = driver.FindElement(By.Id("department-select"));
        MakeElementVisible(jobPosition);
        SelectElement selectJobPosition = new SelectElement(jobPosition);
        selectJobPosition.SelectByValue(job);
 }
예제 #7
0
        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();
        }
        public void CheckParkCostandTimeCase1()
        {
            IWebDriver Driver = new ChromeDriver(@"C:\Users\Rebecca\Documents\Visual Studio 2015\Chrome Driver");

            Driver.Navigate().GoToUrl("http://adam.goucher.ca/parkcalc/index.php");
            Thread.Sleep(2000);

            // Select Short-term Parking from Lot drop down menu
            SelectElement Lot = new SelectElement(Driver.FindElement(By.Id("Lot")));
            Lot.SelectByValue("STP");

            // Enter 10:00 PM in Entry Time, select PM in radio button
            Driver.FindElement(By.Id("EntryTime")).Clear();
            Driver.FindElement(By.Id("EntryTime")).SendKeys("10:00");

            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[2]/td[2]/font/input[3]")).Click();


            //Enter date as 01/01/2014 In Entry Date
            Driver.FindElement(By.Id("EntryDate")).Clear();
            Driver.FindElement(By.Id("EntryDate")).SendKeys("01/01/2014");

            // Enter 11:00 in Exit Time, select PM in radio button
            Driver.FindElement(By.Id("ExitTime")).Clear();
            Driver.FindElement(By.Id("ExitTime")).SendKeys("11:00");

            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[3]/td[2]/font/input[3]")).Click();

            //Enter date as 01/01/2014 In Exit Date
            Driver.FindElement(By.Id("ExitDate")).Clear();
            Driver.FindElement(By.Id("ExitDate")).SendKeys("01/01/2014");

            //Click calculate button, Check cost is equal to $ 2.00, Check duration of stay is (0 Days, 1 Hours, 0 Minutes)
            Driver.FindElement(By.XPath("/html/body/form/input[2]")).Click();
            Thread.Sleep(2000);

            try
            {
                Assert.AreEqual("$ 2.00", Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[2]/span[1]/font/b")).Text);
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }

            try
            {
                Assert.AreEqual("(0 Days, 1 Hours, 0 Minutes)", Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[2]/span[2]/font/b")).Text.Trim());
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }

            // Quit Chrome
            Driver.Quit();
        }
예제 #9
0
 public void ShouldAllowOptionsToBeSelectedByReturnedValue()
 {
     IWebElement element = driver.FindElement(By.Name("select_empty_multiple"));
     SelectElement elementWrapper = new SelectElement(element);
     elementWrapper.SelectByValue("select_2");
     IWebElement firstSelected = elementWrapper.AllSelectedOptions[0];
     Assert.AreEqual("select_2", firstSelected.Text);
 }
 public void GivenIChooseAllFromTheItemsPerPageSelector()
 {
     MKKidsPage kidsPage = (MKKidsPage)ScenarioContext.Current["kidsPage"];
     IWebElement kidsPageItemsSelector = wait.Until(ExpectedConditions.ElementToBeClickable(By.Id(kidsPage.itemsPerPageSelector.GetAttribute("id"))));
     SelectElement itemsPerPageSelector = new SelectElement(kidsPageItemsSelector);
     itemsPerPageSelector.SelectByValue("999999");
     ScenarioContext.Current["kidsPage"] = kidsPage;
 }
예제 #11
0
 /// <summary>
 /// Changes a DropDown selector by value
 /// </summary>
 /// <param name="driver">Current Web Driver</param>
 /// <param name="ddName">'name' value for the selector</param>
 /// <param name="ddValue">Target value</param>
 public static void ChangeDropDownByValue(ref IWebDriver driver, String ddName, String ddValue)
 {
     // Target element
     IWebElement targetElement = driver.FindElement(By.Name(ddName));
     // Create a select element
     SelectElement targetSelector = new SelectElement(targetElement);
     // Change to the value
     targetSelector.SelectByValue(ddValue);
 }
예제 #12
0
 /// <summary>
 /// Enters correct data in the form
 /// </summary>
 public void FilInForm()
 {
     _name.SendKeys("Selenium");
     _cardNumber.SendKeys("4580458045804580");
     SelectElement select = new SelectElement(_expirationDateM);
     select.SelectByValue("11");
     select = new SelectElement(_expirationDateY);
     select.SelectByValue("2019");
     _cvvCode.SendKeys("860");
 }
        public void OpenRegisterPageAndSignUp()
        {

            var randomName = CreateRandomName();

            Logout();


            var mainPageRegisterButton = Driver.FindElement( By.LinkText("Register") );
            mainPageRegisterButton.Click();

            // Text Fields
            var userNameField = Driver.FindElement( By.Id( "profile-user_login" ) );
            userNameField.SendKeys( "devusr_" + randomName );                        

            var emailField = Driver.FindElement( By.Id( "profile-email" ) );
            emailField.SendKeys( "development+devusr_" + randomName + "@weedseeker.net" );
            

            var passwordField = Driver.FindElement( By.Id( "profile-user_pass" ) );
            passwordField.SendKeys( "123456" );

            var confirmPasswordField = Driver.FindElement( By.Id( "profile-user_pass_confirm" ) );
            confirmPasswordField.SendKeys( "123456" );

            // Selects
            var country = Driver.FindElement( By.Id( "profile-country" ) );
            var countrySelectElement = new SelectElement( country );
            countrySelectElement.SelectByValue("224");

            var state = Driver.FindElement( By.Id( "profile-state" ) );
            var stateSelectElement = new SelectElement( state );
            stateSelectElement.SelectByValue( "1525" );

            var city = Driver.FindElement( By.Id( "profile-city" ) );
            var citySelectElement = new SelectElement( city );
            citySelectElement.SelectByValue( "5726" );

            // Checkbox
            var checkboxAgree = Driver.FindElement( By.Name( "agree" ) );
            checkboxAgree.Click();

            // Waits for all AngularJS requests to complete.
            Driver.WaitForAngularJsEventsToComplete();

            //Save Button
            var saveButton = Driver.FindElement( By.CssSelector( "button.btn-success" ) );
            saveButton.Click();

            var alertTitle = Driver.FindElement( By.CssSelector( ".alert-success h4" ) );
            
            Expect(alertTitle, Is.Not.Null);
            Expect(alertTitle.Text, Contains("Account created successfully"));
        }
예제 #14
0
 /// <summary>
 /// Select Dropdown using Value
 /// </summary>
 /// <param name="element">IWebElement</param>
 /// <param name="valueToSelect">Value of the element to Select</param>
 /// <return> N/A </return>
 public void SelectDropDownByValue(IWebElement element, string valueToSelect)
 {
     try
     {
         OpenQA.Selenium.Support.UI.SelectElement selectElement = new OpenQA.Selenium.Support.UI.SelectElement(element);
         selectElement.SelectByValue(valueToSelect);
     }
     catch (Exception ex)
     {
         throw new ConduentUIAutomationException(ex.Message);
     }
 }
예제 #15
0
 public void Select(Element element, string option)
 {
     var select = new SelectElement((IWebElement)element.Native);
     try
     {
         select.SelectByText(option);
     }
     catch (NoSuchElementException)
     {
         select.SelectByValue(option);
     }
 }
        public void All_Steps_With_Minimum_Required_MySQL_Should_Complete()
        {
            // Arrange
            Driver.Navigate().GoToUrl(BaseUrl);
            ClickLanguageLink();

            //
            // ***Act***
            //

            // step 1
            Driver.FindElement(By.CssSelector("button[id=testwebconfig]")).Click();
            Driver.WaitForElementDisplayed(By.CssSelector("#bottom-buttons > a")).Click();

            // step 2
            Driver.FindElement(By.Id("SiteName")).SendKeys("Acceptance tests");
            SelectElement select = new SelectElement(Driver.FindElement(By.Id("DataStoreTypeName")));
            select.SelectByValue(DataStoreType.MySQL.Name);

            Driver.FindElement(By.Id("ConnectionString")).SendKeys(@"server=localhost;database=roadkill;uid=root;pwd=Passw0rd;");
            Driver.FindElement(By.CssSelector("div.continue button")).Click();

            // step 3
            Driver.FindElement(By.CssSelector("div.continue button")).Click();

            // step 3b
            Driver.FindElement(By.Id("AdminEmail")).SendKeys("admin@localhost");
            Driver.FindElement(By.Id("AdminPassword")).SendKeys("password");
            Driver.FindElement(By.Id("password2")).SendKeys("password");
            Driver.FindElement(By.CssSelector("div.continue button")).Click();

            // step 4
            Driver.FindElement(By.CssSelector("input[id=UseObjectCache]")).Click();
            Driver.FindElement(By.CssSelector("div.continue button")).Click();

            // step5
            Assert.That(Driver.FindElement(By.CssSelector(".alert strong")).Text, Is.EqualTo("Installation successful"), Driver.PageSource);
            Driver.FindElement(By.CssSelector(".continue a")).Click();

            // login, create a page
            LoginAsAdmin();
            CreatePageWithTitleAndTags("Homepage", "homepage");

            //
            // ***Assert***
            //
            Driver.Navigate().GoToUrl(BaseUrl);
            Assert.That(Driver.FindElement(By.CssSelector(".pagetitle")).Text, Contains.Substring("Homepage"));
            Assert.That(Driver.FindElement(By.CssSelector("#pagecontent p")).Text, Contains.Substring("Some content goes here"));
        }
예제 #17
0
        public void OpenRegisterPageAndSignUp()
        {

            var randomName = CreateRandomName();

            var mainPageRegisterButton = Driver.FindElement( By.LinkText("Register") );
            mainPageRegisterButton.Click();

            // Text Fields
            var userNameField = Driver.FindElement( By.Id( "profile-user_login" ) );
            userNameField.SendKeys( "devusr_" + randomName );                        

            var emailField = Driver.FindElement( By.Id( "profile-email" ) );
            emailField.SendKeys( "development+" + randomName + "@weedseeker.net" );
            

            var passwordField = Driver.FindElement( By.Id( "profile-user_pass" ) );
            passwordField.SendKeys( "123456" );

            var confirmPasswordField = Driver.FindElement( By.Id( "profile-user_pass_confirm" ) );
            confirmPasswordField.SendKeys( "123456" );

            // Selects
            var country = Driver.FindElement( By.Id( "profile-country" ) );
            var countrySelectElement = new SelectElement( country );
            countrySelectElement.SelectByValue("224");

            var state = Driver.FindElement( By.Id( "profile-state" ) );
            var stateSelectElement = new SelectElement( state );
            stateSelectElement.SelectByValue( "1525" );

            var city = Driver.FindElement( By.Id( "profile-city" ) );
            var citySelectElement = new SelectElement( city );
            citySelectElement.SelectByValue( "5726" );

            // Checkbox
            var checkboxAgree = Driver.FindElement( By.Name( "agree" ) );
            checkboxAgree.Click();

            // Ugly workaround to make sure AngularJS model bindings happened before submitting.
            Driver.WaitForAngularJsModelBinding();

            //Save Button
            var saveButton = Driver.FindElement( By.CssSelector( "button.btn-success" ) );
            saveButton.Click();

            var errorBlock = Driver.FindElement( By.Id( "error_details" ) );
            Assert.Null( errorBlock );
        }
예제 #18
0
		public void All_Steps_With_Minimum_Required(Language language)
		{
			// Arrange
			Driver.Navigate().GoToUrl(BaseUrl);
			ClickLanguageLink(language);

			//
			// ***Act***
			//

			// step 1
			Driver.FindElement(By.CssSelector("button[id=testwebconfig]")).Click();
			Driver.WaitForElementDisplayed(By.CssSelector("#bottom-buttons > a")).Click();

			// step 2
			Driver.FindElement(By.Id("SiteName")).SendKeys("Acceptance tests");
			SelectElement select = new SelectElement(Driver.FindElement(By.Id("DatabaseName")));
			select.SelectByValue("SqlServer2008");

			Driver.FindElement(By.Id("ConnectionString")).SendKeys(TestConstants.CONNECTION_STRING);
			Driver.FindElement(By.CssSelector("div.continue button")).Click();

			// step 3
			Driver.FindElement(By.CssSelector("div.continue button")).Click();

			// step 3b
			Driver.FindElement(By.Id("AdminEmail")).SendKeys("admin@localhost");
			Driver.FindElement(By.Id("AdminPassword")).SendKeys("password");
			Driver.FindElement(By.Id("password2")).SendKeys("password");
			Driver.FindElement(By.CssSelector("div.continue button")).Click();

			// step 4
			Driver.FindElement(By.CssSelector("input[id=UseObjectCache]")).Click();
			Driver.FindElement(By.CssSelector("div.continue button")).Click();

			// step5
			Driver.FindElement(By.CssSelector(".continue a")).Click();

			// login, create a page
			LoginAsAdmin();
			CreatePageWithTitleAndTags("Homepage", "homepage");

			//
			// ***Assert***
			//
			Driver.Navigate().GoToUrl(BaseUrl);
			Assert.That(Driver.FindElement(By.CssSelector(".pagetitle")).Text, Contains.Substring("Homepage"));
			Assert.That(Driver.FindElement(By.CssSelector("#pagecontent p")).Text, Contains.Substring("Some content goes here"));
		}
        public void AnonymousPushModeNotAcceptInvalidValueWhenEditingRepo()
        {
            var repo_id = ITH.CreateRepositoryOnWebInterface(ITH.MakeName());
            app.NavigateTo<RepositoryController>(c => c.Edit(repo_id));
            var form = app.FindFormFor<RepositoryDetailModel>();
            ITH.SetCheckbox(form.Field(f => f.AllowAnonymous).Field, true);
            var select = new SelectElement(form.Field(f => f.AllowAnonymousPush).Field);

            select.SelectByValue(((int)RepositoryPushMode.Global).ToString());

            ITH.SetElementAttribute(select.Options[(int)RepositoryPushMode.Global], "value", "47");
            form.Submit();

            ITH.AssertThatValidationErrorContains(Resources.Repository_Edit_InvalidAnonymousPushMode);
        }
        public void ContentIndex()
        {
            var driver = Driver;
            new NavigateTo(driver).ContentIndexPage();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(50));
            // Select option in menu
            var profileSelect = driver.FindElement(By.Id("selectedProfile"));
            var selectElement = new SelectElement(profileSelect);
            selectElement.SelectByValue(ProfileIds.Diabetes.ToString());

            // Check the content item table contains expected
            var contentItemTable = driver.FindElement(By.ClassName("grid"));
            var text = contentItemTable.Text;
            TestHelper.AssertTextContains(text, "about the data");
        }
        public void Run(IWebDriver webDriver, Step step)
        {
            var s = ((SelectOptionStep) step);
            var element = ElementHelper.GetVisibleElement(webDriver, s.Element);

            var selectElement = new SelectElement(element);
            if (!string.IsNullOrEmpty(s.Value))
            {
                selectElement.SelectByValue(s.Value);
            }
            else
            {
                selectElement.SelectByText(s.Text);
            }
        }
예제 #22
0
        public void Can_Install_SqlServer_Ce_From_Release_Zip_File()
        {
            // Arrange
            string installUrl = "http://roadkill.prerelease.local/";
            LoginUrl = string.Format("{0}/user/login", installUrl);
            Driver.Navigate().GoToUrl(installUrl);

            // Act
            // step 1
            Driver.FindElement(By.CssSelector("input[id=testwebconfig]")).Click();
            Driver.WaitForElementDisplayed(By.CssSelector(".continue > a")).Click();

            // step 2
            Driver.FindElement(By.Id("SiteName")).SendKeys("Acceptance tests");
            SelectElement select = new SelectElement(Driver.FindElement(By.Id("DataStoreTypeName")));
            select.SelectByValue(DataStoreType.SqlServerCe.Name);

            Driver.FindElement(By.Id("ConnectionString")).SendKeys(@"Data Source=|DataDirectory|\roadkill.sdf");
            Driver.FindElement(By.CssSelector("div.continue input")).Click();

            // step 3
            Driver.FindElement(By.CssSelector("div.continue input")).Click();

            // step 3b
            Driver.FindElement(By.Id("AdminEmail")).SendKeys("admin@localhost");
            Driver.FindElement(By.Id("AdminPassword")).SendKeys("password");
            Driver.FindElement(By.Id("password2")).SendKeys("password");
            Driver.FindElement(By.CssSelector("div.continue input")).Click();

            // step 4
            Driver.FindElement(By.CssSelector("input[id=UseObjectCache]")).Click();
            Driver.FindElement(By.CssSelector("div.continue input")).Click();

            // step5
            Assert.That(Driver.FindElement(By.CssSelector("div#installsuccess h1")).Text, Is.EqualTo("Installation successful"), Driver.PageSource);
            Driver.FindElement(By.CssSelector("div#installsuccess a")).Click();

            // login, create a page
            LoginAsAdmin();
            CreatePageWithTitleAndTags("Homepage", "homepage");

            // Assert
            Driver.Navigate().GoToUrl(installUrl);
            Assert.That(Driver.FindElement(By.CssSelector(".pagetitle")).Text, Contains.Substring("Homepage"));
            Assert.That(Driver.FindElement(By.CssSelector("#pagecontent p")).Text, Contains.Substring("Some content goes here"));
        }
예제 #23
0
        public void completePaymentInfo()
        {
            SelectElement paymentType = new SelectElement(this.paymentTypeSelector);
            paymentType.SelectByValue("058b6f07-ac45-46f4-90ce-3f2dd760750e");
            System.Threading.Thread.Sleep(1000);

            this.cardNumberInput.SendKeys("4111111111111111");

            SelectElement paymentMonth = new SelectElement(this.paymentMonthSelector);
            paymentMonth.SelectByValue("02");

            SelectElement paymentYear = new SelectElement(this.paymentYearSelector);
            paymentYear.SelectByValue("2016");

            this.securityCodeInput.SendKeys("156");

        }
예제 #24
0
        /// <summary>
        /// selectの選択
        /// </summary>
        /// <param name="driver"></param>
        private static void EditSelectField(IWebDriver driver)
        {
            // <select>の選択
            // OpenQA.Selenium.Support.UI(NuGet: Selenium.Supportで入る)の
            // SelectElement()を使って選択する
            var element       = driver.FindElement(By.Id("id_selected"));
            var selectElement = new OpenQA.Selenium.Support.UI.SelectElement(element);

            // 選択方法は3種類
            // SelectByIndexは<option>のIndexに一致するもの
            selectElement.SelectByIndex(2);

            // SelectByValueは<option value="1">が一致するもの
            selectElement.SelectByValue("1");

            // SelectByTextは<option>の値が一致するもの
            selectElement.SelectByText("select3");
        }
예제 #25
0
        public bool selectByValue(By locator, string value, string locatorName)
        {
            bool flag = false;

            try
            {
                Select s = new Select(driver.FindElement(locator));
                s.SelectByValue(value);
                flag = true;
            }
            catch (Exception ex)
            {
                flag = false;
                TakeScreenShot();
                throw new Exception(ex.Message);
            }
            return(flag);
        }
        public void EnsureSelectedLanguageIsSaved()
        {
            app.NavigateTo<SettingsController>(c => c.Index());
            var form = app.FindFormFor<GlobalSettingsModel>();
            var langs = new SelectElement(form.Field(f => f.DefaultLanguage).Field);
            Assert.AreNotEqual("de-DE", langs.SelectedOption.GetAttribute("value"));
            langs.SelectByValue("de-DE");
            form.Submit();

            langs = new SelectElement(app.FindDisplayFor<GlobalSettingsModel>().DisplayFor(f => f.DefaultLanguage));
            Assert.AreEqual("de-DE", langs.SelectedOption.GetAttribute("value"));

            /* Set to english again so it is easier to test later */
            form = app.FindFormFor<GlobalSettingsModel>();
            langs = new SelectElement(form.Field(f => f.DefaultLanguage).Field);
            langs.SelectByValue("en-US");
            form.Submit();
        }
예제 #27
0
        public Messages.BaseResult ExecuteTest(OpenQA.Selenium.IWebDriver driverToTest, Parser.TestItem itemToTest)
        {
            BaseResult br = new BaseResult();
            try
            {
                SelectElement selectList;
                IWebElement element;
                SeleniumHtmlHelper helper = new SeleniumHtmlHelper(browserDriver: driverToTest);
                element = helper.ElementLocator(itemToTest.Selector);
                selectList = new SelectElement(element);
                if (itemToTest.Value.StartsWith("label="))
                {
                    selectList.SelectByText(itemToTest.Value.Replace("label=", ""));
                }
                else if (itemToTest.Value.StartsWith("value="))
                {
                    selectList.SelectByValue(itemToTest.Value.Replace("value=", ""));
                }
                else if (itemToTest.Value.StartsWith("id="))
                {
                    element.FindElement(By.XPath(string.Format(@"option[@id='{0}']", itemToTest.Value.Replace("id=", ""))));
                }
                else if (itemToTest.Value.StartsWith("index="))
                {
                    int index = int.Parse(itemToTest.Value.Replace("index=", ""));
                    selectList.SelectByIndex(index);
                }

                br.Status = true;
                br.Message = "OK";
            }
            catch (Exception e)
            {
            #if DEBUG
                throw;
            #endif
                br.Status = false;
                br.Message = string.Format("Exception type: {0}. Message: {1}.", e.GetType(), e.Message);
            }
            return br;
        }
예제 #28
0
        public void UsingSelectBoxes()
        {
            Browser b = new Browser();
            b.SetContent(Helper.GetFromResources("DriverTest.GitHub.htm"));
            IWebDriver driver = new SimpleBrowserDriver(new BrowserWrapper(b));
            var selectbox = driver.FindElement(By.Name("sel"));
            var box = new SelectElement(selectbox);
            Assert.That(box.SelectedOption.Text == "two");
            box.SelectByValue("3");
            Assert.That(box.SelectedOption.Text == "three");
            box.SelectByText("one");
            Assert.That(box.SelectedOption.Text == "one");

			selectbox = driver.FindElement(By.Name("sel_multi"));
			box = new SelectElement(selectbox);
			Assert.That(box.IsMultiple);
			box.SelectByValue("3");
			box.SelectByText("one");
			Assert.That(box.AllSelectedOptions.Count == 3);

		}
예제 #29
0
        public IEnumerable<AdViewModel> GetAllAvailableAds()
        {
            var select = new SelectElement(Driver.FindElement(By.XPath("//div[@id='pager']/form/select")));
            select.SelectByValue("2000");

            var rows = Driver.FindElements(By.XPath("//table/tbody/tr"));

            var ads =
                rows.Select(row => row.FindElements(By.TagName("td")))
                    .Select(
                        columns =>
                        new AdViewModel
                            {
                                AdId = int.Parse(columns[0].Text),
                                BrandId = int.Parse(columns[1].Text),
                                BrandName = columns[2].Text,
                                NumPages = decimal.Parse(columns[3].Text),
                                Position = (Position)Enum.Parse(typeof(Position), columns[4].Text, true)
                            // Take the first 114 arbitrarily to speed up test
                            }).Take(114);

            return ads;
        }
예제 #30
0
        /// <summary>
        /// Select value in dropdown using value attribute.
        /// </summary>
        /// <param name="selectValue">Value to be selected.</param>
        /// <param name="timeout">The timeout.</param>
        public void SelectByValue(string selectValue, double timeout)
        {
            var element = this.WaitUntilDropdownIsPopulated(timeout);

            var selectElement = new SelectElement(element);

            try
            {
                selectElement.SelectByValue(selectValue);
            }
            catch (NoSuchElementException e)
            {
                Logger.Error(CultureInfo.CurrentCulture, "unable to select given value: {0}", selectValue);
                Logger.Error(e.Message);
            }
        }
 private void SetRepoPushTo(Guid repo_id, RepositoryPushMode repositoryPushStatus)
 {
     app.NavigateTo<RepositoryController>(c => c.Edit(repo_id));
     var form = app.FindFormFor<RepositoryDetailModel>();
     var select = new SelectElement(form.Field(f => f.AllowAnonymousPush).Field);
     select.SelectByValue(repositoryPushStatus.ToString("D"));
     form.Submit();
     ITH.AssertThatNoValidationErrorOccurred();
 }
예제 #32
0
 /**
  * 下列选择框根据元素属性值(value)选择, 即value = "foo" , 那么这一项将会被选择:
  * &lt;option value="foo"&gt;Bar&lt;/option&gt;
  * @param locator
  * @param value
  * @see    org.openqa.selenium.support.ui.Select.selectByValue(String value)
  */
 public static void SelectByValue(By locator, String value)
 {
     select = new SelectElement(Driver.FindElement(locator));
     select.SelectByValue(value);
 }
 private void SetGlobalAnonPush(GitInstance git, bool allowAnonymousPush)
 {
     app.NavigateTo<SettingsController>(c => c.Index());
     var form = app.FindFormFor<GlobalSettingsModel>();
     var field =  form.Field(f => f.AllowAnonymousPush);
     ITH.SetCheckbox(field.Field, allowAnonymousPush);
     var languages = new SelectElement(form.Field(f => f.DefaultLanguage).Field);
     languages.SelectByValue("en-US");
     form.Submit();
     ITH.AssertThatNoValidationErrorOccurred();
 }
예제 #34
0
        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);
            });
        }