本文整理汇总了C#中OpenQA.Selenium.Support.UI.SelectElement.SelectByValue方法的典型用法代码示例。如果您正苦于以下问题:C# SelectElement.SelectByValue方法的具体用法?C# SelectElement.SelectByValue怎么用?C# SelectElement.SelectByValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Support.UI.SelectElement
的用法示例。
在下文中一共展示了SelectElement.SelectByValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SelectJobPosition
public void SelectJobPosition(string job)
{
IWebElement jobPosition = driver.FindElement(By.Id("department-select"));
MakeElementVisible(jobPosition);
SelectElement selectJobPosition = new SelectElement(jobPosition);
selectJobPosition.SelectByValue(job);
}
示例2: CopyIndicators
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);
}
示例3: 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);
}
示例4: Type
public AddFieldDialog Type(FieldType type)
{
var element = FindElement("field-type");
var select = new SelectElement(element);
select.SelectByValue(type.ToText());
return this;
}
示例5: 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();
}
示例6: 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);
}
示例7: SelectLocation
public void SelectLocation(string location)
{
IWebElement jobLocation = driver.FindElement(By.Id("location-select"));
MakeElementVisible(jobLocation);
SelectElement selectJobLocation = new SelectElement(jobLocation);
selectJobLocation.SelectByValue(location);
}
示例8: CheckParkCostandTimeCase1
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: GivenIChooseAllFromTheItemsPerPageSelector
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;
}
示例10: ShouldAllowOptionsToBeSelectedByReturnedValue
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);
}
示例11: ChangeDropDownByValue
/// <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: FilInForm
/// <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");
}
示例13: OpenRegisterPageAndSignUp
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: Select
public void Select(Element element, string option)
{
var select = new SelectElement((IWebElement)element.Native);
try
{
select.SelectByText(option);
}
catch (NoSuchElementException)
{
select.SelectByValue(option);
}
}
示例15: All_Steps_With_Minimum_Required_MySQL_Should_Complete
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("[email protected]");
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"));
}