本文整理汇总了C#中ISearchContext类的典型用法代码示例。如果您正苦于以下问题:C# ISearchContext类的具体用法?C# ISearchContext怎么用?C# ISearchContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISearchContext类属于命名空间,在下文中一共展示了ISearchContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindElements
/// <summary>
/// Finds many elements
/// </summary>
/// <param name="context">Context used to find the element.</param>
/// <returns>A readonly collection of elements that match.</returns>
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (this.bys.Length == 0)
{
return new List<IWebElement>().AsReadOnly();
}
List<IWebElement> elems = null;
foreach (By by in this.bys)
{
List<IWebElement> newElems = new List<IWebElement>();
if (elems == null)
{
newElems.AddRange(by.FindElements(context));
}
else
{
foreach (IWebElement elem in elems)
{
newElems.AddRange(elem.FindElements(by));
}
}
elems = newElems;
}
return elems.AsReadOnly();
}
示例2: FindElements
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
// Create script arguments
object[] scriptArgs = new object[this.args.Length + 1];
scriptArgs[0] = this.RootElement;
Array.Copy(this.args, 0, scriptArgs, 1, this.args.Length);
// Get JS executor
IJavaScriptExecutor jsExecutor = context as IJavaScriptExecutor;
if (jsExecutor == null)
{
IWrapsDriver wrapsDriver = context as IWrapsDriver;
if (wrapsDriver != null)
{
jsExecutor = wrapsDriver.WrappedDriver as IJavaScriptExecutor;
}
}
if (jsExecutor == null)
{
throw new NotSupportedException("Could not get an IJavaScriptExecutor instance from the context.");
}
ReadOnlyCollection<IWebElement> elements = jsExecutor.ExecuteScript(this.script, scriptArgs) as ReadOnlyCollection<IWebElement>;
if (elements == null)
{
elements = new ReadOnlyCollection<IWebElement>(new List<IWebElement>(0));
}
return elements;
}
示例3: CreateBys
public static IEnumerable<By> CreateBys(ISearchContext context, MemberInfo member)
{
string platform = GetPlatform(context);
string automation = GetAutomation(context);
IEnumerable<By> defaultBys = CreateDefaultLocatorList(member);
ReadOnlyCollection<By> defaultByList = new List<By>(defaultBys).AsReadOnly();
IEnumerable<By> nativeBys = CreateNativeContextLocatorList(member, platform, automation);
IList<By> nativeByList = null;
if (nativeBys == null)
nativeByList = defaultByList;
else
nativeByList = new List<By>(nativeBys).AsReadOnly();
Dictionary<ContentTypes, IEnumerable<By>> map = new Dictionary<ContentTypes, IEnumerable<By>>();
map.Add(ContentTypes.HTML, defaultByList);
map.Add(ContentTypes.NATIVE, nativeByList);
ContentMappedBy by = new ContentMappedBy(map);
List<By> bys = new List<By>();
bys.Add(by);
return bys.AsReadOnly();
}
示例4: LocateElement
/// <summary>
/// Locates an element using the given <see cref="ISearchContext"/> and list of <see cref="By"/> criteria.
/// </summary>
/// <param name="searchContext">The <see cref="ISearchContext"/> object within which to search for an element.</param>
/// <param name="bys">The list of methods by which to search for the element.</param>
/// <returns>An <see cref="IWebElement"/> which is the first match under the desired criteria.</returns>
public IWebElement LocateElement(ISearchContext searchContext, IEnumerable<By> bys)
{
if (searchContext == null)
{
throw new ArgumentNullException("searchContext", "searchContext may not be null");
}
if (bys == null)
{
throw new ArgumentNullException("bys", "List of criteria may not be null");
}
string errorString = null;
foreach (var by in bys)
{
try
{
return searchContext.FindElement(by);
}
catch (NoSuchElementException)
{
errorString = (errorString == null ? "Could not find element by: " : errorString + ", or: ") + by;
}
}
throw new NoSuchElementException(errorString);
}
示例5: EnterData
public void EnterData(ISearchContext context, IWebElement element, object data)
{
var options = findOptions(element);
foreach (var option in options)
{
if (option.Text == data.ToString())
{
option.Click();
return;
}
}
foreach (var option in options)
{
if (option.GetAttribute("value") == data.ToString())
{
option.Click();
return;
}
}
var message = "Cannot find the desired option\nThe available options are\nDisplay/Key\n";
foreach (var option in options)
{
message += "\n" + "{0}/{1}".ToFormat(option.Text, option.GetAttribute("value"));
}
StoryTellerAssert.Fail(message);
}
示例6: WebElement
/// <summary>
/// Initializes a new instance of the <see cref="WebElement" /> class.
/// </summary>
/// <param name="searchContext">The driver used to search for elements.</param>
protected internal WebElement(ISearchContext searchContext)
{
this.searchContext = searchContext;
this.bys = new List<By>();
this.Cache = true;
}
示例7: RelatedOppsSections
public RelatedOppsSections(ISearchContext context)
: base(context)
{
Element("Title", By.CssSelector(".contact-opportunity__name"));
Element("Stage", By.CssSelector(".contact-opportunity .contact-opportunity__status:nth-of-type(1)"));
Element("Value", By.CssSelector(".contact-opportunity .contact-opportunity__status:nth-of-type(2)"));
}
示例8: TestSearchContext
public TestSearchContext(TestSettings settings, By selfSelector, ISearchContext context,Func<IWebElement> selfLookup)
{
_settings = settings;
_selfSelector = selfSelector;
_context = context;
_selfLookup = selfLookup;
}
示例9: AssertElementPresent
public static void AssertElementPresent(ISearchContext context, By searchBy, string elementDescription)
{
if (!IsElementPresent(context, searchBy))
{
throw new AssertionException(String.Format("AssertElementPresent Failed: Could not find '{0}'", elementDescription));
}
}
示例10: SetUp
public void SetUp()
{
mocks = new Mockery();
mockDriver = mocks.NewMock<ISearchContext>();
mockElement = mocks.NewMock<IWebElement>();
mockExplicitDriver = mocks.NewMock<IWebDriver>();
}
示例11: FindElements
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
var scriptExecutor = DriverWrapperUnwrapper.GetDriverImplementationOf<IJavaScriptExecutor>(context);
EnsureScriptIsLoaded(scriptExecutor);
IEnumerable<object> scriptResult = null;
object executeScript;
if (context is IWebElement)
{
executeScript = scriptExecutor.ExecuteScript("return " + resultPrefix + javascriptGlobal + "(" + selector + ", arguments[0])" + resultPosftix, context);
}
else
{
executeScript = scriptExecutor.ExecuteScript("return " + resultPrefix + javascriptGlobal + "(" + selector + ")" + resultPosftix);
}
scriptResult = (IEnumerable<object>)executeScript;
var result = new ReadOnlyCollection<IWebElement>(scriptResult.Cast<IWebElement>().ToList());
return result;
}
示例12: WebElementProxy
/// <summary>
/// Initializes a new instance of the <see cref="WebElementProxy"/> class.
/// </summary>
/// <param name="searchContext">The driver used to search for elements.</param>
/// <param name="bys">The list of methods by which to search for the element.</param>
/// <param name="cache"><see langword="true"/> to cache the lookup to the element; otherwise, <see langword="false"/>.</param>
/// <param name="locatorFactory">The <see cref="IElementLocatorFactory"/> implementation that
/// determines how elements are located.</param>
internal WebElementProxy(ISearchContext searchContext, IEnumerable<By> bys, bool cache, IElementLocatorFactory locatorFactory)
{
this.locatorFactory = locatorFactory;
this.searchContext = searchContext;
this.bys = bys;
this.cache = cache;
}
示例13: FindTextbox
public static IWebElement FindTextbox(ISearchContext context, IWebElement element)
{
var id = element.GetAttribute("id");
var labelId = id + "Value";
return context.FindElement(By.Id(labelId));
}
示例14: FindElements
/// <summary>
/// Finds many elements
/// </summary>
/// <param name="context">Context used to find the element.</param>
/// <returns>A readonly collection of elements that match.</returns>
public override ReadOnlyCollection<IWebElement> FindElements(ISearchContext context)
{
if (this.bys.Length == 0)
{
return new List<IWebElement>().AsReadOnly();
}
IEnumerable<IWebElement> elements = null;
foreach (By by in this.bys)
{
ReadOnlyCollection<IWebElement> foundElements = by.FindElements(context);
if (foundElements.Count == 0)
{
// Optimization: If at any time a find returns no elements, the
// only possible result for find-all is an empty collection.
return new List<IWebElement>().AsReadOnly();
}
if (elements == null)
{
elements = foundElements;
}
else
{
elements = elements.Intersect(by.FindElements(context));
}
}
return elements.ToList().AsReadOnly();
}
示例15: Execute
/// <summary>
/// Executes the specified context.
/// </summary>
/// <param name="context">The context.</param>
/// <returns></returns>
public IEnumerable<SearchResult> Execute(ISearchContext context)
{
using (var session = this._dbFunction.CreateSession())
{
return session.GetTyped<SearchResult>(r => r.executesearch(context));
}
}