本文整理汇总了C#中OpenQA.Selenium.Support.UI.SelectElement.SelectByIndex方法的典型用法代码示例。如果您正苦于以下问题:C# SelectElement.SelectByIndex方法的具体用法?C# SelectElement.SelectByIndex怎么用?C# SelectElement.SelectByIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Support.UI.SelectElement
的用法示例。
在下文中一共展示了SelectElement.SelectByIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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();
}
示例2: 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);
}
示例3: 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();
}
示例4: 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);
}
示例5: Step2DeliveryOptions
public void Step2DeliveryOptions()
{
var StatementDropdownSelect = new SelectElement(StatementDropdown);
var TaxDropdownSelect = new SelectElement(TaxDropdown);
StatementDropdownSelect.SelectByIndex(new Random().Next(1,2));
TaxDropdownSelect.SelectByIndex(new Random().Next(1, 2));
NextButton.Click();
}
示例6: ShouldAllowOptionsToBeSelectedByIndex
public void ShouldAllowOptionsToBeSelectedByIndex()
{
IWebElement element = driver.FindElement(By.Name("select_empty_multiple"));
SelectElement elementWrapper = new SelectElement(element);
elementWrapper.SelectByIndex(1);
IWebElement firstSelected = elementWrapper.AllSelectedOptions[0];
Assert.AreEqual("select_2", firstSelected.Text);
}
示例7: Create
public void Create()
{
var restaurantList = new SelectElement(Driver.Instance.FindElement(By.Id("RestaurantId")));
restaurantList.SelectByIndex(1);
Driver.Instance.FindElement(By.Id("Body")).SendKeys("Incroybalement mauvais");
Driver.Instance.FindElement(By.Id("Rating")).SendKeys("1");
Driver.Instance.FindElement(By.Id("create_button")).Click();
}
示例8: IFilloutAdvancedForm
public void IFilloutAdvancedForm()
{
IWebElement mission = driver.FindElement(By.Id(EditOrganizationDOMElements.MissionStatementInputId));
mission.SendKeys("Sample mission");
IWebElement donation = driver.FindElement(By.Id(EditOrganizationDOMElements.DonationDescriptionInputId));
donation.SendKeys("Sample donation description");
SelectElement pickup = new SelectElement(driver.FindElement(By.Id(EditOrganizationDOMElements.PickupSelectId)));
pickup.SelectByIndex(1);
donation.Submit();
}
示例9: ChooseElementInList
public static void ChooseElementInList(IWebDriver driver, string name, int elementIndex)
{
try
{
WaitLoop(indice =>
{
var selectElement = new SelectElement(driver.FindElement(By.Name(name)));
selectElement.SelectByIndex(elementIndex);
});
}
catch (Exception ex)
{
var msgErro = string.Format("Erro selecionando inddice, {0} no elemento.: {1}", elementIndex, name);
throw new InvalidOperationException(msgErro, ex);
}
}
示例10: AddBook
public void AddBook(string bookName, int[] bookAuthors)
{
AddBookButton.Click();
WaitUntil(_driver, CustomExpectedConditions.ElementIsVisible(BookNameField), TimeSpan.FromSeconds(10));
BookNameField.SendKeys(bookName);
WaitUntil(_driver, CustomExpectedConditions.ElementIsVisible(SelectedAuthorsField), TimeSpan.FromSeconds(10));
SelectElement SelectedAuthorsSelect = new SelectElement(SelectedAuthorsField);
foreach(int authorId in bookAuthors)
SelectedAuthorsSelect.SelectByIndex(authorId);
WaitUntil(_driver, CustomExpectedConditions.ElementIsVisible(SubmitBookButton), TimeSpan.FromSeconds(10));
SubmitBookButton.Click();
WaitForSuccessAjax(_driver, TimeSpan.FromSeconds(10));
WaitUntil(this._driver, CustomExpectedConditions.ElementIsNotPresent(By.ClassName("blockUI")), TimeSpan.FromSeconds(10));
}
示例11: CheckProfilesPerIndicatorPopup
public static void CheckProfilesPerIndicatorPopup(IWebDriver driver)
{
// Click show me which profiles these indicators are in
var profilePerIndicator = driver.FindElement(By.Id(FingertipsIds.ProfilePerIndicator));
profilePerIndicator.Click();
// Wait for indicator menu to be visible in pop up
var byIndicatorMenu = By.Id(FingertipsIds.ListOfIndicators);
new WaitFor(driver).ExpectedElementToBeVisible(byIndicatorMenu);
// Select 2nd indicator in list
var listOfIndicators = driver.FindElement(byIndicatorMenu);
var selectMenu = new SelectElement(listOfIndicators);
selectMenu.SelectByIndex(1);
// Check list of profiles is displayed
var listOfProfiles = driver.FindElements(By.XPath(XPaths.ListOfProfilesInPopup));
Assert.IsTrue(listOfProfiles.Count > 0);
}
示例12: AddNewDropdown
public void AddNewDropdown()
{
SwitchToPopUps();
SelectElement se = new SelectElement(BrowserDriver.Instance.Driver.FindElement(By.Id("lookupListIdSelect")));
// se.SelectByText("Item1");
se.SelectByIndex(1);
Thread.Sleep(2000);
SwitchToPopUps();
new SelectElement(BrowserDriver.Instance.Driver.FindElement(By.Id("lookupListIdSelect"))).SelectByText("Admin - Locale Supported Language Codes");
Thread.Sleep(2000);
// ((IJavaScriptExecutor)BrowserDriver.Instance.Driver).ExecuteScript("document.getElementById('lookupListIdSelect').selectedIndex ='2'");
javascriptClick(By.XPath(General.Default.NewB));
typeDataName("description", "ABAutomation");
Thread.Sleep(2000);
javascriptClick(By.XPath(General.Default.CreateB));
// IWebElement ele = BrowserDriver.Instance.Driver.FindElement(By.XPath(General.Default.CreateB));
// ele.Click();
Thread.Sleep(2000);
SwitchToPopUps();
}
示例13: ExecuteTest
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;
}
示例14: test1
public void test1()
{
IWebElement FirmEdit = driver.FindElement(By.Id("contentPlaceHolder_txtCompanyName"));
FirmEdit.Click();
FirmEdit.Clear();
FirmEdit.SendKeys(getRandomString(10, 55));
/* IWebElement WebSiteEdit = driver.FindElement(By.Id("contentPlaceHolder_txtWebSite"));
WebSiteEdit.Click();
WebSiteEdit.Clear();
WebSiteEdit.SendKeys(getRandomString(10,55)); */
/* IWebElement NameEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtName"));
NameEdit.Click();
NameEdit.Clear();
NameEdit.SendKeys(getRandomString(10,55)); */
IWebElement Street1Edit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtStreetAddress"));
Street1Edit.Click();
Street1Edit.Clear();
Street1Edit.SendKeys(getRandomString(10, 55));
/* IWebElement Street2Edit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtStreetAddress2"));
FirmEdit.Click();
FirmEdit.Clear();
FirmEdit.SendKeys(getRandomString(10,55));*/
IWebElement CityEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtCity"));
CityEdit.Click();
CityEdit.Clear();
CityEdit.SendKeys(getRandomString(10,55));
IWebElement StateEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_lstState"));
SelectElement selectList = new SelectElement(StateEdit);
selectList.SelectByIndex(random.Next(1, 55));
IWebElement ZipEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtZip"));
ZipEdit.Click();
ZipEdit.Clear();
ZipEdit.SendKeys(getRandomString(10, 55));
IWebElement PhoneEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtPhone"));
PhoneEdit.Click();
PhoneEdit.Clear();
PhoneEdit.SendKeys(getRandomString(10, 55));
/* IWebElement FaxEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtFax"));
FaxEdit.Click();
FaxEdit.Clear();
FaxEdit.SendKeys(getRandomString(10, 55)); */
IWebElement NextButton = driver.FindElement(By.Id("contentPlaceHolder_btnNext"));
NextButton.Click();
// Вторая страница
try
{
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtFirstName")));
}
catch (WebDriverTimeoutException e)
{
Assert.Fail("Second page was not loaded");
}
String firstName = "";
firstName = getRandomString(5, 16);
IWebElement FirstNameEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtFirstName"));
FirstNameEdit.Click();
FirstNameEdit.Clear();
FirstNameEdit.SendKeys(firstName);
String lastName = "";
lastName = getRandomString(5, 16);
IWebElement LastNameEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtLastName"));
LastNameEdit.Click();
LastNameEdit.Clear();
LastNameEdit.SendKeys(lastName);
IWebElement Phone2Edit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtPhone"));
Phone2Edit.Click();
Phone2Edit.Clear();
Phone2Edit.SendKeys(getRandomString(10, 55));
String emailToSend = "";
emailToSend += getRandomString(5, 25);
emailToSend += "@";
emailToSend += getRandomString(3, 10);
emailToSend += ".";
emailToSend += getRandomString(3, 10);
IWebElement EmailEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtEmail"));
EmailEdit.Click();
EmailEdit.Clear();
EmailEdit.SendKeys(emailToSend);
IWebElement SecondEmailEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtSecondEmail"));
SecondEmailEdit.Click();
//.........这里部分代码省略.........
示例15: test4
public void test4()
{
IWebElement FirmEdit = driver.FindElement(By.Id("contentPlaceHolder_txtCompanyName"));
FirmEdit.Click();
FirmEdit.Clear();
FirmEdit.SendKeys(getRandomString(10, 55));
IWebElement Street1Edit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtStreetAddress"));
Street1Edit.Click();
Street1Edit.Clear();
Street1Edit.SendKeys(getRandomString(10, 55));
IWebElement CityEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtCity"));
CityEdit.Click();
CityEdit.Clear();
CityEdit.SendKeys(getRandomString(10, 55));
IWebElement StateEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_lstState"));
SelectElement selectList = new SelectElement(StateEdit);
selectList.SelectByIndex(random.Next(1, 55));
IWebElement ZipEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtZip"));
ZipEdit.Click();
ZipEdit.Clear();
ZipEdit.SendKeys(getRandomString(10, 55));
String phoneToSend = getRandomString(10, 55);
IWebElement PhoneEdit = driver.FindElement(By.Id("contentPlaceHolder_locations_Location0_txtPhone"));
PhoneEdit.Click();
PhoneEdit.Clear();
PhoneEdit.SendKeys(""); // предполагаем, что пользователь забыл ввести одно из полей, так как на
// на всех полях данной формы причина ошибки и сама ошибка идентичные
IWebElement NextButton = driver.FindElement(By.Id("contentPlaceHolder_btnNext"));
NextButton.Click();
try
{
bool isErrorDisplayed = driver.FindElement(By.Id("contentPlaceHolder_valSummary")).Displayed;
}
catch(StaleElementReferenceException)
{
Assert.Fail("Error was not displayed");
}
PhoneEdit.Click();
PhoneEdit.SendKeys(phoneToSend);
NextButton.Click();
// Вторая страница
try
{
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(By.Id("ctl00_contentPlaceHolder_btnNext")));
}
catch (WebDriverTimeoutException e)
{
Assert.Fail("Second page was not loaded");
}
// Очищаем все поля на проверку полей на ошибку отстутсвия содержания в них
IWebElement FirstNameEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtFirstName"));
FirstNameEdit.Clear();
IWebElement LastNameEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtLastName"));
LastNameEdit.Clear();
IWebElement Phone2Edit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtPhone"));
Phone2Edit.Clear();
IWebElement EmailEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtEmail"));
EmailEdit.Clear();
IWebElement SecondEmailEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_newUserInfoEditor_txtSecondEmail"));
SecondEmailEdit.Clear();
IWebElement PasswordEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_passwordControl_txtPassword"));
PasswordEdit.Clear();
IWebElement PasswordConfirmEdit = driver.FindElement(By.Id("ctl00_contentPlaceHolder_passwordControl_txtPasswordConfirm"));
PasswordConfirmEdit.Clear();
// Нажимаем на submit, ожидаем всплывающее окно с ошибкой и парсим ее, проверяя на валидность
IWebElement NextButton2 = driver.FindElement(By.Id("ctl00_contentPlaceHolder_btnNext"));
NextButton2.Click();
wait.Until(ExpectedConditions.AlertIsPresent());
IAlert errorWindow = driver.SwitchTo().Alert();
String errorWindowText = errorWindow.Text;
bool emptyFirstNameError = errorWindowText.Contains("- Enter first name");
bool emptyLastNameError = errorWindowText.Contains("- Enter last name");
bool emptyPhoneError = errorWindowText.Contains("- Enter phone");
bool emptyEmailError = errorWindowText.Contains("- Enter email");
bool emptyConfirmEmailError = errorWindowText.Contains("- Confirm email");
bool emptyPasswordError = errorWindowText.Contains("- Enter password");
bool emptyConfirmPasswordError = errorWindowText.Contains("- Confirm password");
bool allEmptyFieldsError = emptyFirstNameError && emptyLastNameError && emptyPhoneError &&
emptyEmailError && emptyConfirmEmailError && emptyPasswordError && emptyConfirmPasswordError;
//.........这里部分代码省略.........