本文整理汇总了C#中By类的典型用法代码示例。如果您正苦于以下问题:C# By类的具体用法?C# By怎么用?C# By使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
By类属于命名空间,在下文中一共展示了By类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestSearchContext
public TestSearchContext(TestSettings settings, By selfSelector, ISearchContext context,Func<IWebElement> selfLookup)
{
_settings = settings;
_selfSelector = selfSelector;
_context = context;
_selfLookup = selfLookup;
}
示例2: FindElements
public ReadOnlyCollection<IWebElement> FindElements(By @by)
{
var element = _context as IWebElement;
return new EagerReadOnlyCollection<IWebElement>(() =>
(element != null
? TestInteractionWrapper.Interact(ref element, _selfSelector, () => _selfLookup(),
lmnt => _selfLookup().FindElements(@by))
: _context.FindElements(@by))
.Select((lmnt, index) =>
{
//each element must be able to re-resolve it self
//in this case, re-resolve all elements again and just pick the
//element that has the same index as before
return new TestWebElement(_settings, lmnt, @by, this,
ctx =>
{
var children = _selfLookup == null
? _context.FindElements(@by)
: _selfLookup().FindElements(@by);
return children.ElementAt(index);
});
})
);
}
示例3: Lookup
/// <summary>
/// Lookup a reference field value.
/// </summary>
/// <param name="driver"></param>
/// <param name="by">A mechanism by which to find the desired reference field within the current document.</param>
/// <param name="sendKeys">A property value of the current reference field.</param>
public static void Lookup(this IWebDriver driver, By by, string sendKeys)
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
IWebElement lookup = wait.Until(ExpectedConditions.ElementIsVisible(by));
lookup.Click();
string currentWindowHandle = driver.CurrentWindowHandle;
string searchWindow = driver.WindowHandles.First(o => o != currentWindowHandle);
driver.SwitchTo().Window(searchWindow);
IWebElement searchFor = wait.Until(ExpectedConditions.ElementExists(By.ClassName("list_search_text")));
searchFor.Click();
searchFor.Clear();
searchFor.SendKeys(sendKeys);
var selects = driver.FindElements(By.ClassName("list_search_select"));
IWebElement search = selects.First(o => o.GetAttribute("id").Contains("_select"));
driver.SelectOption(search, "Name"); //"for text");
wait.Until(ExpectedConditions.ElementIsVisible(By.CssSelector("img[title='Go']"))).Click();
IWebElement item = wait.Until(ExpectedConditions.ElementExists(By.LinkText(sendKeys)));
item.Click();
driver.SwitchTo().Window(currentWindowHandle);
driver.SwitchTo().Frame("gsft_main");
}
示例4: PolicyResultCacheStrategy
public PolicyResultCacheStrategy(string controllerName, string actionName, Type policyType, Cache cacheLifecycle, By cacheLevel = By.ControllerAction)
{
ControllerName = controllerName;
ActionName = actionName;
PolicyType = policyType;
CacheLifecycle = cacheLifecycle;
CacheLevel = cacheLevel;
}
示例5: ElementPresent
/// <summary>
/// Waits for the element to be present present with a optional time.
/// </summary>
/// <param name="browser">The browser.</param>
/// <param name="locator">The locator.</param>
/// <param name="timeSpan">The time span.</param>
public static void ElementPresent(IWebDriver browser, By locator, TimeSpan? timeSpan = null)
{
if (timeSpan == null)
{
timeSpan = TimeSpan.FromSeconds(10);
}
WaitForElement(browser, locator, (TimeSpan) timeSpan);
}
示例6: FindElements
public static ReadOnlyCollection<IWebElement> FindElements(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => (drv.FindElements(by).Count > 0) ? drv.FindElements(by) : null);
}
return driver.FindElements(by);
}
示例7: FindElement
public static IWebElement FindElement(this IWebDriver driver, By by, int timeoutInSeconds)
{
if (timeoutInSeconds > 0)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeoutInSeconds));
return wait.Until(drv => drv.FindElement(by));
}
return driver.FindElement(by);
}
示例8: ByIdOrName
/// <summary>
/// Initializes a new instance of the <see cref="ByIdOrName"/> class.
/// </summary>
/// <param name="elementIdentifier">The ID or Name to use in finding the element.</param>
public ByIdOrName(string elementIdentifier)
{
if (string.IsNullOrEmpty(elementIdentifier))
{
throw new ArgumentException("element identifier cannot be null or the empty string", "elementIdentifier");
}
this.elementIdentifier = elementIdentifier;
this.idFinder = By.Id(this.elementIdentifier);
this.nameFinder = By.Name(this.elementIdentifier);
}
示例9: Find
public RankedPair Find(By findBy)
{
if (persons.Count < 2)
return new RankedPair();
var pairListing = (from person in persons
from person1 in persons.Skip(persons.IndexOf(person) + 1)
select person.BirthDate < person1.BirthDate ? new RankedPair(person, person1) : new RankedPair(person1, person)).OrderBy(x => x.AgeGap);
return findBy == By.Closest ? pairListing.First() : pairListing.Last();
}
示例10: IsElementPresent
private bool IsElementPresent(By by)
{
try
{
driver.FindElement(by);
return true;
}
catch (NoSuchElementException)
{
return false;
}
}
示例11: HasElement
public static bool HasElement(this IWebDriver driver, By by)
{
try
{
driver.FindElement(by);
}
catch (NoSuchElementException)
{
return false;
}
return true;
}
示例12: isPresent
public static bool isPresent(this IWebDriver driver, By bylocator)
{
bool variable = false;
try
{
IWebElement element = driver.FindElement(bylocator);
variable = element != null;
}
catch (NoSuchElementException)
{
}
return variable;
}
示例13: ElementIsVisible
/// <summary>
/// An expectation for checking that an element is present on the DOM of a page
/// and visible. Visibility means that the element is not only displayed but
/// also has a height and width that is greater than 0.
/// </summary>
/// <param name="locator">The locator used to find the element.</param>
/// <returns>The <see cref="IWebElement"/> once it is located and visible.</returns>
public static Func<IWebDriver, IWebElement> ElementIsVisible(By locator)
{
return (driver) =>
{
try
{
return ElementIfVisible(driver.FindElement(locator));
}
catch (StaleElementReferenceException)
{
return null;
}
};
}
示例14: Highlight
public void Highlight(By locator, bool reset)
{
IWebElement element;
try
{
element = _driver.FindElement(locator);
}
catch (Exception)
{
return;
}
HighlightElement(element, reset);
}
示例15: FindElement
public IWebElement FindElement(By @by)
{
var element = _context as IWebElement;
if (element != null)
{
//Console.WriteLine("element->element: {0}", @by);
return TestInteractionWrapper.Interact(
ref element,
_selfSelector,
() => _selfLookup(),
lmnt => new TestWebElement(_settings, lmnt, _selfSelector, this, ctx => ctx.FindElement(@by))
);
}
//context is IWebDriver, no need to guard for stale element
//Console.WriteLine("driver->element: {0}", @by);
element = _context.FindElement(@by);
return new TestWebElement(_settings, element, @by, _context, ctx => ctx.FindElement(@by));
}