本文整理汇总了C#中Utility.First方法的典型用法代码示例。如果您正苦于以下问题:C# Utility.First方法的具体用法?C# Utility.First怎么用?C# Utility.First使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Utility
的用法示例。
在下文中一共展示了Utility.First方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver)
{
try
{
string v = Value.Contains("$randomNumber") ? Value.Replace("$randomNumber", r.Next(100000, 999999).ToString()) : Value;
IWebElement[] elements;
try
{
elements = new Utility().GetTargetElements(driver, Target);
}
catch (StaleElementReferenceException ex)
{
//retrying
elements = new Utility().GetTargetElements(driver, Target);
}
if (elements.Length == 0)
return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) };
if (elements.Length > 1)
return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) };
elements.First().Clear();
elements.First().SendKeys(v.Remove(v.Length - 2));
//minimum of two letters
for (int i = v.Length - 2; i < v.Length; i++ )
{
elements.First().SendKeys(v[i].ToString());
Thread.Sleep(1000);
}
return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
}
catch (TimeoutException ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message };
}
catch (Exception ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message };
}
}
示例2: Execute
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver)
{
try
{
if (!string.IsNullOrEmpty(Value))
{
Target = Target + "|text=" + Value;
}
IWebElement[] elements = new IWebElement[0];
try
{
elements = new Utility().GetTargetElements(driver, Target);
}
catch (StaleElementReferenceException ex)
{
//retrying
System.Diagnostics.Debug.WriteLine("Retrying..");
elements = new Utility().GetTargetElements(driver, Target);
}
finally
{
if (elements.Length == 1)
{
try
{
elements.First().Click();
}
catch (ElementNotVisibleException ex)
{
elements = new Utility(0).GetTargetElements(driver, Target);
elements.First().Click();
}
}
}
if (elements.Length > 1)
return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) };
if (elements.Length == 0)
return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) };
return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
}
catch (TimeoutException ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message };
}
catch (Exception ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message };
}
}
示例3: Execute
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver)
{
try
{
bool isFound = false;
IWebElement[] elements = null;
try
{
elements = new Utility().GetTargetElements(driver, Target);
}
catch (StaleElementReferenceException ex)
{
//retrying
elements = new Utility().GetTargetElements(driver, Target);
}
finally
{
if (elements.Length == 1)
{
var elements2 = elements.First().FindElements(By.TagName("option"));
foreach (IWebElement el in elements2)
{
if (el.Text == Value)
{
el.Click();
isFound = true;
break;
}
}
}
}
if (elements.Length==0)
return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) };
if (isFound)
return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
else
return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = string.Empty };
}
catch (TimeoutException ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message };
}
catch (Exception ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message };
}
}
示例4: Execute
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver)
{
try
{
IWebElement[] elements;
try
{
elements = new Utility().GetTargetElements(driver, Target);
}
catch (StaleElementReferenceException ex)
{
//retrying
elements = new Utility().GetTargetElements(driver, Target);
}
IWebElement[] elements2;
try
{
elements2 = new Utility().GetTargetElements(driver, Target);
}
catch (StaleElementReferenceException ex)
{
//retrying
elements2 = new Utility().GetTargetElements(driver, Target);
}
if (elements.Length == 0 || elements2.Length == 0)
return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Error Command: {1} Cannot find targets.", "DragAndDrop") };
if (elements.Length > 1 || elements2.Length > 1)
return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for targets") };
(new Actions(driver)).DragAndDrop(elements.First(), elements2.First()).Perform();
return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
}
catch (TimeoutException ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message + "\n" + ex.StackTrace };
}
catch (Exception ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message + "\n" + ex.StackTrace };
}
}
示例5: Execute
public CommandExecutionResult Execute(OpenQA.Selenium.IWebDriver driver)
{
try
{
IWebElement[] elements;
try
{
elements = new Utility().GetTargetElements(driver, Target);
}
catch (StaleElementReferenceException ex)
{
//retrying
elements = new Utility().GetTargetElements(driver, Target);
}
if (elements.Length > 1)
return new CommandExecutionResult { CommandResult = CommandResult.ResultYieldedMoreThanOne, Message = string.Format("More than one element found for target:{0} value:{1}", Target, Value) };
if (elements.Length == 0)
return new CommandExecutionResult { CommandResult = CommandResult.CannotFindElement, Message = string.Format("Cannot find target:{0} value:{1}", Target, Value) };
string text = elements.First().Text;
if (RuntimeValues.ContainsKey(Value))
{
RuntimeValues[Value] = text;
}
else
{
RuntimeValues.Add(Value, text);
}
return new CommandExecutionResult { CommandResult = CommandResult.Success, Message = string.Empty };
}
catch (TimeoutException ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.TimedOut, Message = ex.Message };
}
catch (Exception ex)
{
return new CommandExecutionResult { CommandResult = CommandResult.Failed, Message = ex.Message };
}
}