本文整理汇总了C#中IWebDriver类的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver类的具体用法?C# IWebDriver怎么用?C# IWebDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IWebDriver类属于命名空间,在下文中一共展示了IWebDriver类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Logout
public void Logout(IWebDriver driverToUse = null)
{
if (driverToUse == null)
driverToUse = driver;
driverToUse.FindElement(By.Id("LoginStatus1")).Click();
}
示例2: TrySetupSteps
private void TrySetupSteps(DriverType driverType, SeleniteTest test, IWebDriver webDriver)
{
if (test.TestCollection.SetupSteps.IsNullOrNotAny())
return;
var fileName = String.IsNullOrWhiteSpace(test.TestCollection.SetupStepsFile)
? test.TestCollection.ResolvedFile
: test.TestCollection.SetupStepsFile;
foreach (var pair in _setupStepsMap)
{
if (pair.Key.Target != webDriver)
continue;
if (pair.Value.Any(f => String.Equals(f, fileName, StringComparison.InvariantCultureIgnoreCase)))
return;
}
foreach (var setupStep in test.TestCollection.SetupSteps)
_testService.ExecuteTest(webDriver, driverType, setupStep, true);
var weakReference = new WeakReference(webDriver);
var testFiles = new List<string> { fileName };
_setupStepsMap.Add(weakReference, testFiles);
}
示例3: HandleSeleneseCommand
protected override object HandleSeleneseCommand(IWebDriver driver, string pattern, string ignored)
{
string text = string.Empty;
IWebElement body = driver.FindElement(By.XPath("/html/body"));
IJavaScriptExecutor executor = driver as IJavaScriptExecutor;
if (executor == null)
{
text = body.Text;
}
else
{
text = JavaScriptLibrary.CallEmbeddedHtmlUtils(driver, "getTextContent", body).ToString();
}
text = text.Trim();
string strategyName = "implicit";
string use = pattern;
if (TextMatchingStrategyAndValueRegex.IsMatch(pattern))
{
Match textMatch = TextMatchingStrategyAndValueRegex.Match(pattern);
strategyName = textMatch.Groups[1].Value;
use = textMatch.Groups[2].Value;
}
ITextMatchingStrategy strategy = textMatchingStrategies[strategyName];
return strategy.IsAMatch(use, text);
}
示例4: GetElementXPath
public static string GetElementXPath(IWebElement webElement, IWebDriver webDriver)
{
IJavaScriptExecutor jsExec = webDriver as IJavaScriptExecutor;
return (string)jsExec.ExecuteScript(
@"
function getPathTo(element) {
if (element === document.body)
return '/html/' + element.tagName.toLowerCase();
var ix = 0;
var siblings = element.parentNode.childNodes;
for (var i = 0; i < siblings.length; i++) {
var sibling = siblings[i];
if (sibling === element)
{
return getPathTo(element.parentNode) + '/' + element.tagName.toLowerCase() + '[' + (ix + 1) + ']';
}
if (sibling.nodeType === 1 && sibling.tagName === element.tagName)
ix++;
}
}
var element = arguments[0];
var xpath = '';
xpath = getPathTo(element);
return xpath;
", webElement);
}
示例5: LaunchBrowser
public IWebDriver LaunchBrowser(Browser browser)
{
switch (browser)
{
case Browser.IE:
driver = StartIEBrowser();
break;
case Browser.Chrome:
driver = StartChromeBrowser();
break;
case Browser.Safari:
driver = StartSafariBrowser();
break;
case Browser.Firefox:
default:
driver = StartFirefoxBrowser();
break;
}
driver.Manage().Cookies.DeleteAllCookies();
SetBrowserSize();
var eDriver = new EventedWebDriver(driver);
return eDriver.driver;
}
示例6: Run
public void Run(IWebDriver webDriver, Step step)
{
var e = ((ElementHasStyleStep)step);
try
{
var element = ElementHelper.GetVisibleElement(webDriver, e.Element);
string style = element.GetAttribute("style");
var styles = style.Split(';').Select(x =>
{
var parts = x.Replace(" ", "").Split(':');
if (parts.Length != 2) return null;
return new Style(parts[0], parts[1]);
}).Where(x => x != null).ToList();
if (styles.All(x => x.Key != e.StyleKey))
throw new StepException(string.Format("The element '{0}' did not have the '{1}' style.", e.Element,
e.StyleKey));
if (!styles.Any(x => x.Key == e.StyleKey && x.Value == e.StyleValue))
throw new StepException(
string.Format("The element '{0}' had the '{1}' style, but it's value was not '{2}'.", e.Element,
e.StyleKey, e.StyleValue));
}
catch (NoSuchElementException ex)
{
throw new StepException(string.Format("The document does not contain an element that matches '{0}'.",
e.Element));
}
}
示例7: TouchActions
/// <summary>
/// Initializes a new instance of the <see cref="TouchActions"/> class.
/// </summary>
/// <param name="driver">The <see cref="IWebDriver"/> object on which the actions built will be performed.</param>
public TouchActions(IWebDriver driver)
: base(driver)
{
IHasTouchScreen touchScreenDriver = driver as IHasTouchScreen;
if (touchScreenDriver == null)
{
IWrapsDriver wrapper = driver as IWrapsDriver;
while (wrapper != null)
{
touchScreenDriver = wrapper.WrappedDriver as IHasTouchScreen;
if (touchScreenDriver != null)
{
break;
}
wrapper = wrapper.WrappedDriver as IWrapsDriver;
}
}
if (touchScreenDriver == null)
{
throw new ArgumentException("The IWebDriver object must implement or wrap a driver that implements IHasTouchScreen.", "driver");
}
this.touchScreen = touchScreenDriver.TouchScreen;
}
示例8: HandleSeleneseCommand
protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
{
string tableString = string.Empty;
if (!TableParts.IsMatch(locator))
{
throw new SeleniumException("Invalid target format. Correct format is tableName.rowNum.columnNum");
}
Match tableMatch = TableParts.Match(locator);
string tableName = tableMatch.Groups[0].Value;
long row = int.Parse(tableMatch.Groups[1].Value, CultureInfo.InvariantCulture);
long col = int.Parse(tableMatch.Groups[2].Value, CultureInfo.InvariantCulture);
IWebElement table = finder.FindElement(driver, tableName);
string script =
"var table = arguments[0]; var row = arguments[1]; var col = arguments[2];" +
"if (row > table.rows.length) { return \"Cannot access row \" + row + \" - table has \" + table.rows.length + \" rows\"; }" +
"if (col > table.rows[row].cells.length) { return \"Cannot access column \" + col + \" - table row has \" + table.rows[row].cells.length + \" columns\"; }" +
"return table.rows[row].cells[col];";
object returnValue = JavaScriptLibrary.ExecuteScript(driver, script, table, row, col);
IWebElement elementReturned = returnValue as IWebElement;
if (elementReturned != null)
{
tableString = ((IWebElement)returnValue).Text.Trim();
}
else
{
throw new SeleniumException(returnValue.ToString());
}
return tableString;
}
示例9: ManageQueueSection
ManageQueueSection(
IWebDriver webBrowserDriver)
: base(webBrowserDriver)
{
this.QueueInformation = new QueueInformationSection(webBrowserDriver);
this.QueueClient = new QueueClientSection(webBrowserDriver);
}
示例10: Selectanoption
public void Selectanoption(IWebDriver driver, By by, string optiontoselect)
{
var data = driver.FindElement(@by);
//IList<IWebElement> dataoptions = data.FindElements(By.TagName("option"));
var select = new SelectElement(data);
@select.SelectByText(optiontoselect);
}
示例11: SearchPage
public SearchPage(IWebDriver driver)
{
this.driver = driver;
Boolean isPresent = driver.FindElement(By.CssSelector("#btnFTPOutputFile")).Size > 0;
if (isPresent == false)
throw new NoSuchElementException("This is not the Search page");
}
示例12: TestCleanup
public void TestCleanup()
{
if (Properties.Settings.Default.BROWSER == BrowserType.Ie)
{
driver.Quit();
driver = null;
}
try
{
if (MyBook.Name != "")
{
MyBook.Save();
MyBook.Close();
}
if (MyApp.Name != "")
{
MyApp.Quit();
}
}catch
{ }
KillProcess("EXCEL");
KillProcess("IEDriverServer");
KillProcess("iexplore");
}
示例13: Login
public void Login()
{
driver = new InternetExplorerDriver();
try
{
//Run before any test
driver.Navigate().GoToUrl(url + "MDM");
driver.FindElement(By.Id("userNameTextBox")).SendKeys(user);
driver.FindElement(By.Id("passwordTextBox")).SendKeys(password);
driver.FindElement(By.Id("loginBtn")).Click();
Common.WaitForElement(driver, By.ClassName("breadcrumbs"), 30);
}
catch (TimeoutException e)
{
System.Console.WriteLine("TimeoutException: " + e.Message);
Assert.Fail(e.Message);
}
catch (NoSuchElementException e)
{
Assert.Fail(e.Message);
}
catch (Exception e)
{
System.Console.WriteLine("unhandled exception: " + e.Message);
Assert.Fail(e.Message);
}
}
示例14: Start
public static void Start(BrowserType browserType = BrowserType.Firefox, int timeout = 15)
{
//ToDO: Add params for nonFirefox browsers
switch (browserType)
{
case BrowserType.Firefox:
WebDriver = new FirefoxDriver();
break;
case BrowserType.Ie:
WebDriver = new ChromeDriver();
break;
case BrowserType.Chrome:
WebDriver = new ChromeDriver();
break;
case BrowserType.Edge:
WebDriver = new EdgeDriver();
break;
case BrowserType.PhantomJs:
WebDriver = new PhantomJSDriver();
break;
default:
throw new ArgumentOutOfRangeException(nameof(browserType), browserType, null);
}
BrowserWait = new WebDriverWait(WebDriver, TimeSpan.FromSeconds(timeout));
}
示例15: Specify
public override void Specify()
{
given("the browser is firefox", delegate
{
Browser = arrange(() => new FirefoxBrowser());
go();
});
// maybe support skip remaining tests if any have failed so far?
given("the browser is internet explorer", delegate
{
Browser = arrange(() => new InternetExplorerBroser());
go();
});
given("the browser is chrome", delegate
{
Browser = arrange(() => new ChromeBrowser());
go();
});
}