本文整理汇总了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);
}
示例2: OneHundredRecordsOnPage
public static void OneHundredRecordsOnPage()
{
var domainesDropdown = Driver.Instance.FindElement(By.Name("domain-datatables_length"));
var selectNumberOfDomaines = new SelectElement(domainesDropdown);
selectNumberOfDomaines.SelectByText("100");
}
示例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();
}
}
示例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();
}
示例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"));
}
}
示例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 + "'");
}
}
示例7: SelectByText
public void SelectByText(string text)
{
IWebElement webElement = _pageElement.WebDriver.WaitForElement(_pageElement.By);
SelectElement selectElement = new SelectElement(webElement);
selectElement.SelectByText(text);
}
示例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 "));
//}
}
}
示例9: SelectCurrency
public MessageAndAmount SelectCurrency(string currencyCode)
{
var currencyCodeSelect = new SelectElement(_currencyCodeDropdown);
currencyCodeSelect.SelectByText(currencyCode);
return this;
}
示例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);
}
示例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();
}
}
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}