本文整理汇总了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();
}
}
示例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();
}
示例3: OneHundredRecordsOnPage
public static void OneHundredRecordsOnPage()
{
var domainesDropdown = Driver.Instance.FindElement(By.Name("domain-datatables_length"));
var selectNumberOfDomaines = new SelectElement(domainesDropdown);
selectNumberOfDomaines.SelectByText("100");
}
示例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();
}
示例5: Type
public AddFieldDialog Type(FieldType type)
{
var element = FindElement("field-type");
var select = new SelectElement(element);
select.SelectByValue(type.ToText());
return this;
}
示例6: SelectCurrency
public MessageAndAmount SelectCurrency(string currencyCode)
{
var currencyCodeSelect = new SelectElement(_currencyCodeDropdown);
currencyCodeSelect.SelectByText(currencyCode);
return this;
}
示例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();
}
示例8: SelectByText
public void SelectByText(string text)
{
IWebElement webElement = _pageElement.WebDriver.WaitForElement(_pageElement.By);
SelectElement selectElement = new SelectElement(webElement);
selectElement.SelectByText(text);
}
示例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;
}
示例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);
}
示例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);
}
示例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 + "'");
}
}
示例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;
}
示例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();
}
}
}
}
示例15: FindSelectOptionByValue
public static IWebElement FindSelectOptionByValue(SelectElement selectElement, string value)
{
var option = selectElement.Options
.FirstOrDefault(x => x.GetAttribute("value") == value);
return option;
}