本文整理汇总了C#中OpenQA.Selenium.By.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# By.ToString方法的具体用法?C# By.ToString怎么用?C# By.ToString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.By
的用法示例。
在下文中一共展示了By.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoNotExist
public IElementAssert DoNotExist(By findExpression, string message = null, TimeSpan maxWait = default(TimeSpan))
{
return DoNotExist(() => Find.Element(findExpression, maxWait), findExpression.ToString(), message);
}
示例2: FindElements
public ReadOnlyCollection<IWebElement> FindElements(By @by)
{
if (@by.ToString().Contains("value"))
return new ReadOnlyCollection<IWebElement>(_childElements);
if(@by.ToString().Contains("text"))
return new ReadOnlyCollection<IWebElement>(_childElements);
return null;
}
示例3: GetElement
public static IWebElement GetElement(By locator)
{
if (IsElemetPresent(locator))
return ObjectRepository.Driver.FindElement(locator);
else
throw new NoSuchElementException("Element Not Found : " + locator.ToString());
}
示例4: WaitForElement
public void WaitForElement(By by)
{
try
{
WebDriverWait wait = new WebDriverWait(this.driver, waitForElement);
wait.Until(ExpectedConditions.VisibilityOfAllElementsLocatedBy(by));
}
catch
{
throw new TimeoutException(string.Format("Element with locator: {0} was not found in {1} seconds!", by.ToString(), secondsToWait));
}
}
示例5: BuildStillCheckedExceptionText
private string BuildStillCheckedExceptionText(By by, BaseTestDriver ext)
{
StringBuilder sb = new StringBuilder();
string customLoggingMessage =
String.Format("#### The element with the location strategy: {0} ####\n ####WAS CHECKED!####",
by.ToString());
sb.AppendLine(customLoggingMessage);
string cuurentUrlMessage = String.Format("The URL when the test failed was: {0}", ext.Browser.Url);
sb.AppendLine(cuurentUrlMessage);
return sb.ToString();
}
示例6: BuildElementStillVisibleExceptionText
private string BuildElementStillVisibleExceptionText(By by, BaseWebDriverTest ext)
{
StringBuilder sb = new StringBuilder();
string customLoggingMessage =
String.Format("#### The element with the location strategy: {0} ####\n ####IS STILL VISIBLE!####",
by.ToString());
sb.AppendLine(customLoggingMessage);
string cuurentUrlMessage = String.Format("The URL when the test failed was: {0}", ext.Browser.Url);
sb.AppendLine(cuurentUrlMessage);
return sb.ToString();
}
示例7: IsElementNotDisplayed
public bool IsElementNotDisplayed(By element)
{
try
{
Driver.FindElement(element);
return false;
}
catch (NoSuchElementException e)
{
return true;
}
catch (Exception e)
{
Console.WriteLine("Something is wrong came to exception instead of NoSuchelementException -- IsElementNotDisplayed({0}) -- Exception >> {1}",element.ToString(),e.Message);
return false;
}
}
示例8: WaitForElement
/**
* Will wait for a specified web element to appear. If not found
* an assertion will fail.
*
* @param by The description of the element
* @return The matching element if found.
*/
public static IWebElement WaitForElement(By by)
{
for (int second = 0; ; second++)
{
if (second >= timeOut)
{
Execute.Assertion.FailWith("Timeout occurred while waiting for: " + by.ToString());
}
try
{
return GetWebDriver().FindElement(by);
}
catch (Exception)
{
Thread.Sleep(1000);
}
}
}
示例9: WaitForElement
public static IWebElement WaitForElement(this IWebDriver driver, By by, TimeSpan timeout)
{
var wait = new WebDriverWait(driver, timeout);
return wait.Until((d) =>
{
var value = default(IWebElement);
try
{
value = d.FindElement(by);
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine("Error detected while locating element {0}: ", by.ToString(), e.Message);
}
return value;
});
}
示例10: WaitForNotChecked
public void WaitForNotChecked(By by)
{
IWebElement currentElement = this.GetElement(by);
bool isSelected = currentElement.Selected;
if (!isSelected)
{
Log.ErrorFormat("The element with find expression {0} was checked.", by.ToString());
throw new StillCheckedException(by, this);
}
}
示例11: setBy
/// <summary>
/// Defines the locator parts ("How" and "Using"), sets the current By locator and uses that By locator to set the current element
/// </summary>
/// <param name="by">Current By value</param>
public void setBy(By by)
{
//Split the By locator into the "How" and "Using" parts
arrLocator = by.ToString().Split(':');
this.by = by;
//Set the current element
this.element = getDriver().FindElement(getBy());
}
示例12: WaitForNotVisible
public static void WaitForNotVisible(this IWebDriver driver, By by, int timeout = 0)
{
if (timeout == 0) timeout = Config.Settings.runTimeSettings.ElementTimeoutSec;
var then = DateTime.Now.AddSeconds(timeout);
for (var now = DateTime.Now; now < then; now = DateTime.Now)
{
var eles = driver.FindElements(by);
if (eles.Count == 0 || !eles[0].Displayed)
return;
Common.Delay(1000);
}
throw new ElementNotVisibleException(string.Format("Element ({0}) was still visible after {1} seconds",
by.ToString(), timeout));
}
示例13: ReadElementAttributes
internal static Dictionary<string, string> ReadElementAttributes(By by, IWebDriver webDriver)
{
/*
*
[
{
"Key": "href",
"Value": "http://example.com"
},
{
"Key": "class",
"Value": " "
}
]
*/
var result = new Dictionary<string, string>();
var elements = webDriver.FindElements(by);
if (elements.Count == 0)
{
throw new NotFoundException("ReadElementAttributes: Element was not found" + by.ToString());
}
var currentElement = elements[0];
IJavaScriptExecutor jsExec = webDriver as IJavaScriptExecutor;
string json = (string)jsExec.ExecuteScript(
@"
var jsonResult = ""[\n"";
var attrs = arguments[0].attributes;
for (var l = 0; l < attrs.length; ++l) {
var a = attrs[l];
var name = a.name.replace(/\\/g, ""\\\\"").replace(/\""/g, ""\\\"""");
var value = a.value.replace(/\\/g, ""\\\\"").replace(/\""/g, ""\\\"""");
jsonResult += '{ ""Key"": ""' + name + '"", ""Value"": ""' + value + '""},';
}
jsonResult += ""]\n"";
return jsonResult;
", currentElement);
MyLog.Write("JSON:\n" + json);
var attributesList = DeserializeAttributesFromJson(json);
foreach (var attr in attributesList)
{
result.Add(attr.Key, attr.Value);
}
result.Add("TagName", currentElement.TagName);
return result;
}
示例14: SelectByText
/// <summary>Selects an option from a select box based on text
/// <para> @param by - the by selector for the given element </para>
/// <para> @param optionText - the text to select by </para>
/// </summary>
internal void SelectByText(By by, string optionText)
{
if (_logActions)
{
_logger.LogMessage(string.Format("Selct: {0}", optionText));
_logger.LogMessage(string.Format(" at: {0}", by));
}
var select = new SelectElement(Find(by));
if (!select.Equals(null))
{
try
{
select.SelectByText(optionText);
}
catch
{
var errMsg = String.Format(
"PageObjectBase: There is no option '{0}' in {1}.",
optionText, by);
throw new InvalidSelectOptionException(errMsg);
}
}
else
{
string errMsg = "Cannot find element " + by.ToString();
throw new NoSuchElementException(errMsg);
}
}
示例15: Find
/// <summary>Finds the element by the given selector
/// <para> @param by - the by selector for the given element</para>
/// </summary>
protected IWebElement Find(By by)
{
var _stopwatch = new Stopwatch();
_stopwatch.Start();
while (_driver.FindElements(by).Count == 0)
{
if (_stopwatch.ElapsedMilliseconds > _defaultTimeout)
{
throw new NoSuchElementException("Could not find element " + by.ToString());
}
}
_stopwatch.Stop();
_stopwatch.Reset();
return _driver.FindElement(by);
}