本文整理汇总了C#中OpenQA.Selenium.By类的典型用法代码示例。如果您正苦于以下问题:C# By类的具体用法?C# By怎么用?C# By使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
By类属于OpenQA.Selenium命名空间,在下文中一共展示了By类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindElementsWithTimeoutWait
/// <summary>
/// Finds the elements with timeout wait.
/// </summary>
/// <param name="driver">The driver.</param>
/// <param name="by">The by.</param>
/// <returns></returns>
public static ReadOnlyCollection<IWebElement> FindElementsWithTimeoutWait(IWebDriver driver, By by)
{
Exception ex = null;
ReadOnlyCollection<IWebElement> e = null;
long elapsedTime = 0;
while (elapsedTime < TimeOut)
{
try
{
elapsedTime++;
StandardSleep(1);
e = driver.FindElements(by);
break;
}
catch (NoSuchElementException nse)
{
if (e == null)
throw ex;
}
}
if (e == null)
throw ex;
return e;
}
示例2: FindElements
private IEnumerable<INativeElement> FindElements(By by)
{
var elements = _context.FindElements(by);
foreach (var element in elements)
yield return new WebDriverNativeElement(element);
}
示例3: ScrollToAndClick
public static void ScrollToAndClick(By locator)
{
IWebElement element = GenericHelper.GetElement(locator);
ExecuteScript("window.scrollTo(0," + element.Location.Y + ")");
Thread.Sleep(300);
element.Click();
}
示例4: ElementIsDisplayed
public static bool ElementIsDisplayed(this IWebDriver driver, By by)
{
System.Threading.Thread.Sleep(5);
IWebElement el;
bool isDisplayed = false;
bool gotBoolean;
if (driver.ElementExists(by))
{
el = driver.FindElement(by);
do
{
// For whatever reason, on Android this often throws an InvalidCastException
try
{
isDisplayed = el.Displayed;
gotBoolean = true;
} catch (InvalidCastException)
{
// Loop until we get either a true or false
gotBoolean = false;
}
} while (gotBoolean == false);
return isDisplayed;
}
else
{
return false;
}
}
示例5: Element
public Element(string element)
{
if (string.IsNullOrEmpty(element))
return;
// assume XPath expression
if (element.Contains("/"))
{
this.element = By.XPath(element);
return;
}
var token = element.Split('=');
if (token.Length != 2)
return;
var key = token[0].Trim().ToLower();
var value = token[1].Trim();
if ("id".Equals(key))
{
this.element = By.Id(value);
}
else if ("name".Equals(key))
{
this.element = By.Name(value);
}
else if ("link".Equals(key))
{
this.element = By.LinkText(value);
}
}
示例6: GetElements
public IList<IWebElement> GetElements(By by)
{
if (Tag == null)
throw new NullReferenceException("You can't call GetElements on a block without first initializing Tag.");
return Tag.FindElements(by);
}
示例7: CreateNewPortal
public static void CreateNewPortal(IWebDriver driver, string portalName, By template)
{
Login.AsHost(driver);
driver.Navigate().GoToUrl(SiteManagementPage);
driver.WaitClick(CreatePortalButton);
driver.WaitClick(AddSiteSiteTypeChildRadio);
driver.FindDnnElement(AddSitePortalAliasTextbox).Clear();
driver.WaitSendKeys(AddSitePortalAliasTextbox, "localhost/DotNetNuke_Enterprise/" + portalName + "/");
driver.FindDnnElement(AddSitePortalAliasTextbox).Clear();
driver.WaitSendKeys(AddSitePortalAliasTextbox, "localhost/DotNetNuke_Enterprise/" + portalName + "/");
driver.WaitSendKeys(AddSitePortalNameTextbox, portalName);
driver.WaitClick(AddSiteTemplateInput);
driver.WaitClick(template);
driver.WaitClick(AddSiteCreateSiteButton);
int origTimeout = Common.DriverTimeout;
Common.DriverTimeout = 30000;
driver.WaitClick(AddSiteVisitNewPortalLink);
Common.DriverTimeout = origTimeout;
}
示例8: WaitForElementEx
public static IWebElement WaitForElementEx(this ISearchContext node, By condition, int? maxWaitMS = null, int? waitIntervalMS = null)
{
maxWaitMS = maxWaitMS ?? MaxWaitMS;
waitIntervalMS = waitIntervalMS ?? WaitIntervalMS;
DateTime finishTime = DateTime.UtcNow.AddMilliseconds(maxWaitMS.Value);
do
{
DateTime timeAttempted = DateTime.UtcNow;
try
{
return node.FindElement(condition);
}
catch (Exception)
{
if (timeAttempted > finishTime)
{
throw;
}
}
Thread.Sleep(waitIntervalMS.Value);
} while (true);
}
示例9: WaitUntilElementsInvisible
public static IEnumerable<IWebElement> WaitUntilElementsInvisible(this IWebDriver driver, By selector)
{
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
wait.Until(ExpectedConditions.InvisibilityOfElementLocated(selector));
return driver.FindElements(selector);
}
示例10: GetElement
public static IWebElement GetElement(By locator)
{
if (IsElemetPresent(locator))
return ObjectRepository.Driver.FindElement(locator);
else
throw new NoSuchElementException("Element Not Found : " + locator.ToString());
}
示例11: Element
/// <summary>
/// Construct an element
/// </summary>
/// <param name="locator">By locator</param>
public Element(By locator): base()
{
this.name = "Element";
this.by = locator;
this.pageObjectName = TestBase.GetCurrentClassName();
this.timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec;
}
示例12: Element
/// <summary>
/// Construct an element
/// </summary>
/// <param name="locator">By locator</param>
public Element(By locator)
{
name = "Element";
by = locator;
pageObjectName = TestBase.GetCurrentClassName();
timeoutSec = Config.Settings.runTimeSettings.ElementTimeoutSec;
}
示例13: PageElement
protected PageElement(By byLocator)
{
BaseElement = new CCElement(byLocator);
if (ValidTags != null && !ValidTags.Contains(BaseElement.TagName.ToLower())) {
throw new Exception("Tag '" + BaseElement.TagName + "' is not valid");
}
}
示例14: 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));
}
}
示例15: WaitForElementPresentAndEnabled
public void WaitForElementPresentAndEnabled(By locator, int secondsToWait = 30)
{
new WebDriverWait(this.driver, new TimeSpan(0, 0, secondsToWait))
.Until(d => d.FindElement(locator).Enabled
&& d.FindElement(locator).Displayed
);
}