本文整理汇总了C#中ISearchContext.FindElement方法的典型用法代码示例。如果您正苦于以下问题:C# ISearchContext.FindElement方法的具体用法?C# ISearchContext.FindElement怎么用?C# ISearchContext.FindElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISearchContext
的用法示例。
在下文中一共展示了ISearchContext.FindElement方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindTextbox
public static IWebElement FindTextbox(ISearchContext context, IWebElement element)
{
var id = element.GetAttribute("id");
var labelId = id + "Value";
return context.FindElement(By.Id(labelId));
}
示例2: 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);
}
示例3: IsElementPresent
public static bool IsElementPresent(ISearchContext context, By searchBy)
{
try {
var b = context.FindElement(searchBy).Displayed;
return true;
}
catch {
return false;
}
}
示例4: GetText
private string GetText(By xpath, ISearchContext seleniumScope)
{
var pageText = seleniumScope.FindElement(xpath).Text;
return NormalizeCRLFBetweenBrowserImplementations(pageText);
}
示例5: 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;
DateTime endTime = DateTime.Now.Add(this.timeout);
bool timeoutReached = DateTime.Now > endTime;
while (!timeoutReached)
{
foreach (var by in bys)
{
try
{
return searchContext.FindElement(by);
}
catch (NoSuchElementException)
{
errorString = (errorString == null ? "Could not find element by: " : errorString + ", or: ") + by;
}
}
timeoutReached = DateTime.Now > endTime;
if (!timeoutReached)
{
Thread.Sleep(this.pollingInterval);
}
}
throw new NoSuchElementException(errorString);
}
示例6: VerifyRowMatched
private bool VerifyRowMatched(ISearchContext webElement)
{
var values = Data.Split('|');
return values.Select(value => webElement.FindElement(By.XPath("//*[contains(text(),'" + value + "')]"))).All(td => td != null);
}
示例7: ForElement
public static IWebElement ForElement(ISearchContext searchContext,
By by, int millisecondsToWait = DefaultTimeout)
{
var endTime = DateTime.Now.AddMilliseconds(millisecondsToWait);
while (DateTime.Now < endTime)
{
try
{
var element = searchContext.FindElement(by);
return element;
}
catch (NoSuchElementException) { }
}
throw new NoSuchElementException(by + " not found in " +
millisecondsToWait + "ms");
}
示例8: WaitForElement
protected IWebElement WaitForElement(ISearchContext context, By selector)
{
return Wait.For(() => context.FindElement(selector));
}
示例9: FindElement
public static IWebElement FindElement(ISearchContext context, By searchBy, string elementDescription)
{
IWebElement element = null;
try
{
element = context.FindElement(searchBy);
}
catch (NoSuchElementException e)
{
e.ToString();
if (!IsElementPresent(context, searchBy))
throw new AssertionException(string.Format("AssertElementPresent Failed: Could not find '{0}'",
elementDescription));
}
return element;
}
示例10: IsElementPresent
// NOTE: Again as above, this method checks if an element is Displayed as opposed to being present
// Although there is a try and catch and the catch will work just fine if an element is not present.
public static bool IsElementPresent(ISearchContext context, By searchBy, int maxDuration)
{
var retryInterval = 1000; // 1 sec
var maxDuration2 = maxDuration;
var isPresent = false;
while (maxDuration2 > 0)
{
try
{
var b = context.FindElement(searchBy).Displayed;
isPresent = true;
break;
}
catch (Exception ex)
{
Trace.Write(ex.Message);
}
Thread.Sleep(retryInterval);
maxDuration2 -= retryInterval;
}
return isPresent;
}