本文整理汇总了C#中OpenQA.Selenium.Support.UI.SelectElement.DeselectAll方法的典型用法代码示例。如果您正苦于以下问题:C# SelectElement.DeselectAll方法的具体用法?C# SelectElement.DeselectAll怎么用?C# SelectElement.DeselectAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Support.UI.SelectElement
的用法示例。
在下文中一共展示了SelectElement.DeselectAll方法的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: SelectOptions
/// <summary>
/// Selects some options from a multi-select element
/// </summary>
/// <param name="select">the select element</param>
/// <param name="option">the options to select</param>
public static void SelectOptions(IWebElement select, IEnumerable<string> options)
{
SelectElement sourceSelect = new SelectElement(select);
if (sourceSelect.IsMultiple)
{
sourceSelect.DeselectAll();
}
foreach (string option in options)
{
sourceSelect.SelectByText(option);
}
}
示例3: SelectItem
/// <summary>
/// Method to select specified item from list.
/// </summary>
public void SelectItem(string[] itemList, bool selectMultiple = false)
{
string availbleItemsInList = string.Empty;
string expectedItems = string.Empty;
try
{
string firstItem = itemList.First();
expectedItems = itemList.Aggregate(expectedItems, (current, item) => current + string.Format("\t" + item));
_testObject = WaitAndGetElement();
if (_testObject != null)
availbleItemsInList = _testObject.Text;
#region KRYPTON0156: Handling conditions where selectItem can be used for radio groups
if (_testObject != null && (_testObject.GetAttribute("type") != null && _testObject.GetAttribute("type").ToLower().Equals("radio")))
{
string radioValue = string.Empty;
//Check if given option is also stored in mapping column
string valueFromMapping = string.Empty;
foreach (KeyValuePair<string, string> mappingKey in _dicMapping)
{
if (mappingKey.Key.ToLower().Equals(firstItem.ToLower()))
{
valueFromMapping = mappingKey.Value;
break;
}
}
foreach (IWebElement radioObject in _testObjects)
{
//Retrieve value property of radio button and compare with passed text
string tempRadioValue = radioObject.GetAttribute("value");
if (tempRadioValue.ToLower().Equals(firstItem.ToLower()) || tempRadioValue.ToLower().Equals(valueFromMapping.ToLower()))
{
radioValue = tempRadioValue;
_testObject = radioObject;
break;
}
}
//Determine if a radio option was found or not, and take action based on that
if (!radioValue.Equals(string.Empty))
{
ExecuteScript(_testObject, "arguments[0].click();");
return;
}
Property.Remarks = string.Empty;
throw new Exception(Utility.GetCommonMsgVariable("KRYPTONERRCODE0022").Replace("{MSG}", firstItem));
}
#endregion
// Entire section commented above works just fine, but damn slow on IE
//Following code section is a shortcut for the same, and works reliably and fast on all browsers
//Clear previus selection if multiple options needs to be selected
if (selectMultiple)
{
SelectElement select = new SelectElement(_testObject);
select.DeselectAll();
}
bool isSelectionSuccessful = false;
foreach (string optionForSelection in itemList)
{
string optionText = optionForSelection.Trim();
if (_testObject != null)
{
IList<IWebElement> allOptions = _testObject.FindElements(By.TagName("option"));
foreach (IWebElement option in allOptions)
{
try
{
string propertyValue = option.GetAttribute("value");
if (option.Displayed)
{
if (option.Text.Contains(optionText))
{
isSelectionSuccessful = true;
option.Click();
break;
}
if (propertyValue != null && propertyValue.ToLower().Contains(optionText))
{
isSelectionSuccessful = true;
option.Click();
break;
}
}
}
catch (Exception ex)
{
if (ex is StaleElementReferenceException)
{
//.........这里部分代码省略.........
示例4: DeselectItems
/// <summary>
/// Метод сбрасывается значение в элемент типа Select. Причём снимает ВСЕ значения даже если хоть одно должно быть.
/// </summary>
/// <param name="checkErrors">Проверка на ошибки</param>
public void DeselectItems(bool checkErrors = true)
{
var selectElement = new SelectElement(BitrixFramework.FindWebElement(this));
selectElement.DeselectAll();
Log.MesNormal(String.Format("'{0}' -> сбошены сзначения", description));
//проверяем страницу на наличие ошибок
if (checkErrors)
{
BitrixFramework.CheckJSErrors();
GM.CheckContentOnErrors();
}
}
示例5: ShouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelections
public void ShouldNotAllowUserToDeselectAllWhenSelectDoesNotSupportMultipleSelections()
{
IWebElement element = driver.FindElement(By.Name("selectomatic"));
SelectElement elementWrapper = new SelectElement(element);
elementWrapper.DeselectAll();
}
示例6: ShouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections
public void ShouldAllowUserToDeselectAllWhenSelectSupportsMultipleSelections()
{
IWebElement element = driver.FindElement(By.Name("multi"));
SelectElement elementWrapper = new SelectElement(element);
elementWrapper.DeselectAll();
IList<IWebElement> returnedOptions = elementWrapper.AllSelectedOptions;
Assert.AreEqual(0, returnedOptions.Count);
}
示例7: SetValue
public static void SetValue(string controlString, string value)
{
DbConnectionStringBuilder _control = new DbConnectionStringBuilder();
_control.ConnectionString = controlString;
if (! _control.ContainsKey("type"))
{
throw new ArgumentOutOfRangeException("type","The control type has not been implemented in SetValue()");
}
IWebElement _element = GetElement(controlString);
string text;
switch (_control["type"].ToString().ToLower())
{
case "input":
case "text":
case "typetext":
_element.SendKeys(value ?? string.Empty);
WaitForAsyncPostBackToComplete();
break;
case "select":
// if the value to set is empty, ignore it.
if (!string.IsNullOrEmpty(value))
{
WaitForAsyncPostBackToComplete();
SelectElement selectElement = new SelectElement(_element);
selectElement.DeselectAll();
selectElement.SelectByText(value);
WaitForAsyncPostBackToComplete();
}
break;
case "checkbox":
// if the value to set is empty, ignore it.
if (!string.IsNullOrEmpty(value))
{
bool isChecked;
bool.TryParse(value, out isChecked);
// _document.CheckBox(_control.WatinAttribute).Checked = isChecked;
WaitForAsyncPostBackToComplete();
}
break;
case "radiobutton":
// if the value to set is empty, ignore it.
if (!string.IsNullOrEmpty(value))
{
// _document.RadioButton((_control.WatinAttribute) && Find.ByValue(value)).Checked = true;
WaitForAsyncPostBackToComplete(); ;
}
break;
case "fileupload":
// _document.FileUpload(_control.WatinAttribute).Set(value);
WaitForAsyncPostBackToComplete();
break;
default:
throw new NotImplementedException("The control type has not been implemented in Stax.Controller.Watin SetValue()");
}
}
示例8: SelectIndex
public void SelectIndex(Func<IElement> element, int optionIndex)
{
this.Act(() =>
{
var unwrappedElement = element() as Element;
SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
if (selectElement.IsMultiple) selectElement.DeselectAll();
selectElement.SelectByIndex(optionIndex);
});
}
示例9: MultiSelectText
public void MultiSelectText(Func<IElement> element, string[] optionTextCollection)
{
this.Act(() =>
{
var unwrappedElement = element() as Element;
SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
if (selectElement.IsMultiple) selectElement.DeselectAll();
foreach (var optionText in optionTextCollection)
{
selectElement.SelectByText(optionText);
}
});
}
示例10: SelectValue
public void SelectValue(ElementProxy element, string optionValue)
{
this.Act(CommandType.Action, () =>
{
var unwrappedElement = element.Element as Element;
SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
if (selectElement.IsMultiple) selectElement.DeselectAll();
selectElement.SelectByValue(optionValue);
});
}
示例11: SelectIndex
public void SelectIndex(ElementProxy element, int optionIndex)
{
this.Act(CommandType.Action, () =>
{
var unwrappedElement = element.Element as Element;
SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
if (selectElement.IsMultiple) selectElement.DeselectAll();
selectElement.SelectByIndex(optionIndex);
});
}
示例12: MultiSelectText
public void MultiSelectText(ElementProxy element, string[] optionTextCollection)
{
this.Act(CommandType.Action, () =>
{
var unwrappedElement = element.Element as Element;
SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
if (selectElement.IsMultiple) selectElement.DeselectAll();
foreach (var optionText in optionTextCollection)
{
selectElement.SelectByText(optionText);
}
});
}
示例13: MultiSelectIndex
public void MultiSelectIndex(ElementProxy element, int[] optionIndices)
{
this.Act(CommandType.Action, () =>
{
var unwrappedElement = element.Element as Element;
SelectElement selectElement = new SelectElement(unwrappedElement.WebElement);
if (selectElement.IsMultiple) selectElement.DeselectAll();
foreach (var optionIndex in optionIndices)
{
selectElement.SelectByIndex(optionIndex);
}
});
}
示例14: _07_Multyselection_Box_List_Test
public void _07_Multyselection_Box_List_Test()
{
//идем на сайт
driver.Url= "http://toolsqa.com/automation-practice-form/";
//Находим список c выбором по имени и присваеваем его в oSelect
SelectElement oSelect = new SelectElement(driver.FindElement(By.Name("selenium_commands")));
//выбираем первый элемет, 2-х секундная пауза
oSelect.SelectByIndex(0);
System.Threading.Thread.Sleep(2000);
//отменяем выбор, 2-х секундная пауза
oSelect.DeselectByIndex(0);
System.Threading.Thread.Sleep(2000);
//выбираем по содежанию, 2-х секундная пауза
oSelect.SelectByText("Navigation Commands");
System.Threading.Thread.Sleep(2000);
//отменяем выбор, 2-х секундная пауза
oSelect.DeselectByText("Navigation Commands");
System.Threading.Thread.Sleep(2000);
//создаем колекцию всех опций списка
IList<IWebElement> Options = oSelect.Options;
//для каждого вебэлемента в колеции
foreach (IWebElement item in Options)
{
//выводим его текст
Console.WriteLine(item.Text);
//Выбираем его и 1 сек. пауза
item.Click();
System.Threading.Thread.Sleep(1000);
}
//отменяем выбор всех опций 2 сек. пауза
oSelect.DeselectAll();
System.Threading.Thread.Sleep(2000);
}
示例15: deselectAll
/// <summary>
/// Wraps Selenium's method. Unselects all options in the element
/// </summary>
/// <param name="element">Element from which to deselect all options</param>
public void deselectAll(Tuple<locatorType, string> element)
{
//Grab the select element
try
{
innerSelect = new SelectElement(findElement(element));
}
catch (UnexpectedTagNameException utne)
{
TestReporter.log("The element defined by locatoryType ["
+ element.Item1.ToString() + "] and identifier ["
+ element.Item2 + "] is not a select-type element.\n\n"
+ utne.StackTrace);
}
//Deselect all options
innerSelect.DeselectAll();
}