本文整理汇总了C#中OpenQA.Selenium.Firefox.FirefoxDriver.SwitchTo方法的典型用法代码示例。如果您正苦于以下问题:C# FirefoxDriver.SwitchTo方法的具体用法?C# FirefoxDriver.SwitchTo怎么用?C# FirefoxDriver.SwitchTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenQA.Selenium.Firefox.FirefoxDriver
的用法示例。
在下文中一共展示了FirefoxDriver.SwitchTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: testHomePage
/// <summary>
/// Test all links on the Krossover home page
/// </summary>
public void testHomePage(FirefoxDriver driver)
{
string homePage = "http://www.krossover.com/";
driver.Navigate().GoToUrl(homePage);
Thread.Sleep(1000);
//find all links on the page
IList<IWebElement> links = driver.FindElementsByTagName("a");
//loop through all of the links on the page
foreach (IWebElement link in links)
{
try
{
//check if any of the links return a 404
link.SendKeys(Keys.Control + Keys.Enter);
driver.SwitchTo().Window(driver.WindowHandles.Last());
driver.FindElementByXPath("//div[contains(@class, '404')]");
log(link.GetAttribute("href") + " is broken. Returned 404");
driver.SwitchTo().Window(driver.WindowHandles.First());
}
catch
{
//continue to the next link
continue;
}
}
driver.Quit(); //kill the driver
}
示例2: Test2
public void Test2()
{
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://tourism.51book.com/adminLogin.htm");
driver.FindElement(By.Id("userName")).SendKeys("ZLBGYCS");
driver.FindElement(By.Id("password")).SendKeys("123456");
driver.FindElement(By.Id("submit")).Submit();
driver.FindElement(By.XPath("/html/body/table/tbody/tr/td[1]/div/a[1]")).Click();
driver.FindElement(By.Id("nextSteps")).Click();
driver.SwitchTo().DefaultContent();
driver.SwitchTo().Frame("");
}
示例3: Main
static void Main(string[] args)
{
IWebDriver driver;
driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.javascriptsandmore.com/javascript-alert-box.html");
IAlert alert = driver.SwitchTo().Alert();
Console.WriteLine(alert.Text);
alert.Accept();
IAlert next_alert = driver.SwitchTo().Alert();
Console.WriteLine(next_alert.Text);
next_alert.Accept();
driver.Quit();
Console.Read();
}
示例4: WindowProcess_Demo2
public void WindowProcess_Demo2()
{
var articleName = "[小北De编程手记] : Lesson 02 - Selenium For C# 之 核心对象";
_output.WriteLine("Step 01 : 启动浏览器并打开Lesson 01 - Selenium For C#");
IWebDriver driver = new FirefoxDriver();
driver.Url = "http://www.cnblogs.com/NorthAlan/p/5155915.html";
_output.WriteLine("Step 02 : 点击链接打开新页面。");
var lnkArticle02 = driver.FindElement(By.LinkText(articleName));
lnkArticle02.Click();
_output.WriteLine("Step 03 : 根据标题获取新页面的句柄。");
var oldWinHandle = driver.CurrentWindowHandle;
foreach (var winHandle in driver.WindowHandles)
{
driver.SwitchTo().Window(winHandle);
if (driver.Title.Contains(articleName))
{
break;
}
}
_output.WriteLine("Step 04 : 验证新页面标题是否正确。");
var articleTitle = driver.FindElement(By.Id("cb_post_title_url"));
Assert.Equal<string>(articleName, articleTitle.Text);
_output.WriteLine("Step 05 : 关闭浏览器。");
driver.Quit();
}
示例5: WindowProcess_Demo1
public void WindowProcess_Demo1()
{
// 1. 获取窗口定位对象
IWebDriver driver = new FirefoxDriver();
//省略部分代码... ...
ITargetLocator locator = driver.SwitchTo();
driver = locator.Window("windowName");
//后续操作... ...
driver.Quit();
}
示例6: shouldAllLinkLeadSomewhere
public void shouldAllLinkLeadSomewhere()
{
IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://www.theguardian.com");
var mainPage = new MainEntryPage(driver);
listoflinks = mainPage.GetLinks (driver);
for (int n = 0; n < listoflinks.Count; n++) {
Console.WriteLine(listoflinks[n].Text);
var beforeWindow = driver.CurrentWindowHandle;
if (driver.FindElement(By.LinkText(listoflinks[n].Text)).Displayed && listoflinks[n].Text != "Sign in"){
Console.WriteLine("Found link: " + listoflinks[n].Text);
driver.FindElement(By.LinkText(listoflinks[n].Text)).SendKeys(Keys.Shift + Keys.Return);
foreach (string handle in driver.WindowHandles)
{
if (handle != beforeWindow)
{
driver.SwitchTo().Window(handle);
break;
}
}
Console.WriteLine("UJ: " + driver.Url);
driver.Close();
driver.SwitchTo().Window(beforeWindow);
Console.WriteLine("REGI: " + driver.Url);
}
else
{
Console.WriteLine("NotFound link: " + listoflinks[n].Text);
}
//driver.Navigate().Back();
}
}
示例7: Test2
public void Test2()
{
//var driver = new InternetExplorerDriver(@"D:\test file\selenium\IEDriverServer");
//FirefoxProfile firfoxProfile = new FirefoxProfile(@"D:\install\Mozilla Firefox");
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://tourism.51book.com/adminLogin.htm");
driver.FindElement(By.Id("userName")).SendKeys("ZLBGYCS");
driver.FindElement(By.Id("password")).SendKeys("123456");
driver.FindElement(By.Id("submit")).Submit();
driver.FindElement(By.XPath("/html/body/table/tbody/tr/td[1]/div/a[1]")).Click();
System.Collections.Generic.IList<string> handls=driver.WindowHandles;
IWebDriver childeDriver = driver.SwitchTo().Window(handls[1]);
childeDriver.FindElement(By.Id("nextSteps")).Click();
//////childeDriver.SwitchTo().DefaultContent();
//////childeDriver.SwitchTo().Frame(1);
var iframe = childeDriver.FindElement(By.CssSelector("iframe.ke-edit-iframe"));
childeDriver.SwitchTo().Frame(iframe);//进入iframe
childeDriver.FindElement(By.XPath("/html/body")).SendKeys("12345678");//进入body输入数据
}
示例8: Test
public void Test()
{
string testTime = DateTime.Now.ToString("t");
var driver=new FirefoxDriver();
driver.Manage().Window.Maximize();
driver.Navigate().GoToUrl("http://www.51aqy.com/");
driver.FindElement(By.CssSelector("a.xs2-link")).Click();
System.Collections.Generic.IList<string> handles = driver.WindowHandles;//获取窗口数量
IWebDriver chilWindow = driver.SwitchTo().Window(handles[1]);//调转到当前窗口
// chilWindow.Close();//关闭当前窗口
chilWindow.FindElement(By.CssSelector("a.app-data > span.text")).Click();//对当前窗口操作
System.Collections.Generic.IList<string> handles1 = chilWindow.WindowHandles;
IWebDriver TwoWindow = chilWindow.SwitchTo().Window(handles1[1]);
TwoWindow.FindElement(By.Id("input1")).SendKeys("880082993370");
TwoWindow.FindElement(By.Id("input2")).SendKeys("15015015050");
TwoWindow.FindElement(By.CssSelector("button.open-client")).Click();
TwoWindow.FindElement(By.CssSelector("#myModal-no-bangding > div.modal-header > button.close")).Click();
string actualResult = TwoWindow.FindElement(By.CssSelector("div.info > span.info-name ")).Text;
string expectedResult = "尊敬的用户";
Assert.AreEqual(expectedResult, actualResult);
//Console.WriteLine(actualResult);
//将测试结果写入excel
// Helper.NPOIHelper(testTime,expectedResult,actualResult);
log4net.ILog iLog = log4net.LogManager.GetLogger("message");
if (iLog.IsDebugEnabled)
{
iLog.Debug("debug");
}
if (iLog.IsInfoEnabled)
{
iLog.Info("message");
}
driver.Quit();
}
示例9: WindowProcess_Demo3
public void WindowProcess_Demo3()
{
IWebDriver driver = new FirefoxDriver();
//省略部分代码... ...
var oldWinHandle = driver.CurrentWindowHandle;
ITargetLocator locator = driver.SwitchTo();
IAlert winAlert = locator.Alert();
winAlert.Accept(); //确定:Alert , Confirm, Prompt
winAlert.Dismiss(); //取消:Confirm, Prompt
var text = winAlert.Text; //获取提示内容:Alert , Confirm, Prompt
winAlert.SendKeys("input text."); //输入提示文本:Prompt
//后续操作... ...
driver.Quit();
}
示例10: Main
static void Main(string[] args)
{
Console.WriteLine("Please enter the URL (Like :- https://qa-playdays.lego.com )\n\t");
var url = Console.ReadLine();
//var url = "http://google.com";
var path = AppDomain.CurrentDomain.BaseDirectory + "\\Result";
string subject = "Regress Test for " + url;
string str = "<center><table border=1 ><caption><b>Site Tracking : " + subject + "</b></caption>";
str += "<tr><th style='width:700px'>Test Case </th><th style='width:150px;'>Result</th></tr>";
Proxy proxy = new Proxy();
proxy.IsAutoDetect = true;
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.SetCapability(CapabilityType.Proxy, proxy);
IWebDriver driver = new FirefoxDriver(capabilities);
driver.Manage().Cookies.DeleteAllCookies();
driver.Navigate().GoToUrl(url);
driver.Manage().Window.Maximize();
driver.SwitchTo().ParentFrame();
IWebElement scriptTag = null;
try
{
var updatedURL = driver.Url;
var words = updatedURL.Split('/');
var local = words[3].ToLower();
var environment = words[2].ToLower();
try
{
Console.WriteLine("Test Case 1 : Verify the site tracking implementation by checking presence of ‘data-tracking-script’ tag in DOM ");
scriptTag = driver.FindElement(By.CssSelector("script[data-tracking-script]"));
Console.WriteLine("Test Case 1 : Pass - Verify the site tracking implementation by checking presence of ‘data-tracking-script’ tag in DOM");
str += "<tr><td>Test Case 1 : Verify the site tracking implementation by checking presence of ‘data-tracking-script’ tag in DOM </td><td> Pass" + "</td></tr>";
}
catch (Exception)
{
Console.WriteLine("Test Case 1 : Fail - 1. Site tracking implementation by checking presence of ‘data-tracking-script’ tag in DOM");
str += "<tr><td>Test Case 1 : Verify the site tracking implementation by checking presence of ‘data-tracking-script’ tag in DOM </td><td> Fail" + "</td></tr>";
}
if (scriptTag != null)
{
Console.WriteLine("Test Case 2 : Verify URL locale (ex. da-dk) should match with site tracking script tag i.e. cultural-info attribute (da-dk) ");
try
{
var cultureInfo = scriptTag.GetAttribute("culture-info").ToLower();
Console.WriteLine("Locale mention in 'Culture-Info' attribute : " + cultureInfo);
try
{
//Assert.Equals(local, cultureInfo);
if (cultureInfo.Equals(local))
{
Console.WriteLine("Test Case 2 : Pass - Verify URL locale should match with site tracking script tag i.e. cultural-info attribute : " + cultureInfo);
str += "<tr><td>Test Case 2 : Verify URL locale (ex. da-dk) should match with site tracking script tag i.e. cultural-info attribute (da-dk) </td><td> Pass" + "</td></tr>";
}
else if (cultureInfo.Equals("en-us")) // check with Dev End for better implementation
{
Console.WriteLine("Test Case 2 : Pass - Verify URL locale should match with site tracking script tag i.e. cultural-info attribute : " + cultureInfo);
str += "<tr><td>Test Case 2 : Verify URL locale should match with site tracking script tag i.e. cultural-info attribute :" + cultureInfo + " </td><td> Pass" + "</td></tr>";
}
else
{
Console.WriteLine("Test Case 2 : Fail - URL locale should not match with site tracking script tag i.e. cultural-info attribute : " + cultureInfo);
str += "<tr><td>Test Case 2 : Verify URL locale should not match with site tracking script tag i.e. cultural-info attribute :" + cultureInfo + " </td><td> Fail" + "</td></tr>";
}
}
catch (Exception)
{
Console.WriteLine("Test Case 2 : Fail - URL locale should not match with site tracking script tag i.e. cultural-info attribute : " + cultureInfo);
str += "<tr><td>Test Case 2 : URL locale should not match with site tracking script tag i.e. cultural-info attribute :" + cultureInfo + " </td><td> Fail" + "</td></tr>";
}
}
catch (Exception)
{
Console.WriteLine("Test Case 2 : Fail - Because Culture-info Attribute Tag is Missing ");
str += "<tr><td>Test Case 2 : URL locale should not match with site tracking script tag i.e. cultural-info attribute (da-dk) </td><td> Fail" + "</td></tr>";
}
}
if (scriptTag != null)
{
Console.WriteLine("Test Case 3 : Verify ‘Report Suite’ should be as per expectation i.e. for QA it should be 'LegoGlobalQA' and Live it should be 'Global' ");
if (environment.Contains("qa-"))
{
try
{
var dataReportSuite = scriptTag.GetAttribute("data-reportsuite").ToLower();
Console.WriteLine("Report Suite is in 'dataReportSuite' attribute : " + dataReportSuite);
if (dataReportSuite.Equals("legoglobalqa") || dataReportSuite.Contains("qa"))
{
Console.WriteLine("Test Case 3 : Pass - Verify ‘Report Suite’ should be as per expectation i.e. for QA it should be 'LegoGlobalQA' ");
str += "<tr><td>Test Case 3 : Verify ‘Report Suite’ should be as per expectation for QA i.e. " + dataReportSuite + "</td><td> Pass" + "</td></tr>";
}
else
//.........这里部分代码省略.........
示例11: EnterDummyPaymentOptions
private void EnterDummyPaymentOptions(FirefoxDriver seleniumInstance,StripeCardDetails cardDetails)
{
seleniumInstance.SwitchTo().Frame(seleniumInstance.FindElementByCssSelector(".stripe_checkout_app"));
var emailEl = seleniumInstance.FindElementByName("email");
emailEl.SendKeys("[email protected]");
var cardEl = seleniumInstance.FindElementByName("card_number");
cardEl.SendKeys(cardDetails.CardNumber);
var expiresEl = seleniumInstance.FindElementByName("cc-exp");
expiresEl.SendKeys(cardDetails.Expiry);
//var nameOnCard = seleniumInstance.FindElementById("paymentName");
//nameOnCard.SendKeys(cardDetails.CardHolderName);
var cvc = seleniumInstance.FindElementByName("cc-csc");
cvc.SendKeys(cardDetails.CVC);
var submitButton = seleniumInstance.FindElementByCssSelector(".button button");
submitButton.ClickWithJavascript(seleniumInstance);
}
示例12: CorrectUserLogInTest
public void CorrectUserLogInTest()
{
IWebDriver driver = new FirefoxDriver();
string baseURL = "http://www.google.com/ ";
StringBuilder verificationErrors = new StringBuilder();
driver.Navigate().GoToUrl(baseURL);
try
{
Assert.AreEqual("Google", driver.Title);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
driver.FindElement(By.Id("gb_70")).Click();
driver.FindElement(By.Id("Email")).Clear();
driver.FindElement(By.Id("Email")).SendKeys("testqaexam");
driver.FindElement(By.Id("Passwd")).Clear();
driver.FindElement(By.Id("Passwd")).SendKeys("TestPass");
driver.FindElement(By.Id("signIn")).Click();
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if ("[email protected]" == driver.FindElement(By.LinkText("[email protected]")).Text) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.AreEqual("[email protected]", driver.FindElement(By.LinkText("[email protected]")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
// command [selectWindow | null | ]
string currentWindowHadle = driver.CurrentWindowHandle;
driver.SwitchTo().Window(currentWindowHadle);
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if ("[email protected]" == driver.FindElement(By.LinkText("[email protected]")).Text) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.AreEqual("[email protected]", driver.FindElement(By.LinkText("[email protected]")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
driver.FindElement(By.LinkText("[email protected]")).Click();
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if ("Изход" == driver.FindElement(By.Id("gb_71")).Text) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.AreEqual("Изход", driver.FindElement(By.Id("gb_71")).Text);
}
catch (Exception e)
{
verificationErrors.Append(e.Message);
}
driver.FindElement(By.Id("gb_71")).Click();
for (int second = 0; ; second++)
{
if (second >= 60) Assert.Fail("timeout");
try
{
if ("Вход" == driver.FindElement(By.Id("gb_70")).Text) break;
}
catch (Exception)
{ }
Thread.Sleep(1000);
}
try
{
Assert.AreEqual("Вход", driver.FindElement(By.Id("gb_70")).Text);
//.........这里部分代码省略.........
示例13: baiduTest
public void baiduTest()
{
var mainWindow = new FirefoxDriver();
INavigation navigation = mainWindow.Navigate();
navigation.GoToUrl("http://www.baidu.com/");
IWebElement btnMainWindow = mainWindow.FindElement(By.Name("tj_reg"));
btnMainWindow.Click();
System.Collections.Generic.IList<string> handles = mainWindow.WindowHandles;
//for (int i=0;i<handles.Count;i++)
//{
// Console.WriteLine(handles[i]);
//}
//Console.ReadKey();
IWebDriver childWindow = mainWindow.SwitchTo().Window(handles[1]);
IWebElement txchildWindow = childWindow.FindElement(By.Id("TANGRAM__PSP_4__account"));
txchildWindow.SendKeys("1234567");
}
示例14: WindowHandleTest
public void WindowHandleTest()
{
var mainWindow = new FirefoxDriver();
INavigation navigation = mainWindow.Navigate();
navigation.GoToUrl("http://www.hao123.com");
IWebElement btnMainWindow = mainWindow.FindElement(By.XPath("//*[@id='site']/div/ul/li[1]/a"));
btnMainWindow.Click();
System.Collections.Generic.IList<string> handles = mainWindow.WindowHandles; //获取窗口的数量
IWebDriver childWindow = mainWindow.SwitchTo().Window(handles[1]); //定位到第一个窗口
IWebElement textchildWindow = childWindow.FindElement(By.Id("kw"));
textchildWindow.SendKeys("selenium");
IWebElement buttonElement = childWindow.FindElement(By.Id("su"));
buttonElement.Click();
mainWindow.SwitchTo().Window(handles[0]); //回到主窗口
}
示例15: QTest
public void QTest()
{
var driver = new FirefoxDriver();
driver.Navigate().GoToUrl("http://17186.cn/business/business_detail.3.jsp?columnId=92470&resourceCode=208654&version=3&unikey=ea1dd33180794db683bd17868ce4de7a");
var js_displayBlock = string.Format("document.querySelector('#slide_nav').style.display=' block'");
((IJavaScriptExecutor)driver).ExecuteScript(js_displayBlock);
driver.FindElement(By.XPath("//*[@id='slide_nav']/ul/li[2]/div/a/span")).Click();
System.Collections.Generic.IList<string> handles = driver.WindowHandles;
IWebDriver OneHandle = driver.SwitchTo().Window(handles[1]);
}