當前位置: 首頁>>代碼示例>>C#>>正文


C# FirefoxDriver.SwitchTo方法代碼示例

本文整理匯總了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
        }
開發者ID:dhruv0018,項目名稱:Krossover,代碼行數:35,代碼來源:TestHomePage.cs

示例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("");
        }
開發者ID:null2014,項目名稱:SeleniumTest,代碼行數:13,代碼來源:NewTest.cs

示例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();
 }
開發者ID:nat-github,項目名稱:first_github,代碼行數:14,代碼來源:Program.cs

示例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();

        }
開發者ID:DemoCnblogs,項目名稱:Selenium,代碼行數:31,代碼來源:Lesson07_WindowProcess.cs

示例5: WindowProcess_Demo1

 public void WindowProcess_Demo1()
 {
     // 1. 獲取窗口定位對象
     IWebDriver driver = new FirefoxDriver();
     //省略部分代碼... ...
     ITargetLocator locator = driver.SwitchTo();
     driver = locator.Window("windowName");
     //後續操作... ...
     driver.Quit();
 }
開發者ID:DemoCnblogs,項目名稱:Selenium,代碼行數:10,代碼來源:Lesson07_WindowProcess.cs

示例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();
            }
        }
開發者ID:ukpeti,項目名稱:RedBadgeCsharp,代碼行數:39,代碼來源:TestLogin.cs

示例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輸入數據
        }
開發者ID:null2014,項目名稱:SeleniumTest,代碼行數:22,代碼來源:UnitTest1.cs

示例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();
        }
開發者ID:null2014,項目名稱:SeleniumTest,代碼行數:39,代碼來源:51.cs

示例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();

        }
開發者ID:DemoCnblogs,項目名稱:Selenium,代碼行數:17,代碼來源:Lesson07_WindowProcess.cs

示例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
//.........這裏部分代碼省略.........
開發者ID:smriti22,項目名稱:Integration,代碼行數:101,代碼來源:Program.cs

示例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);
        }
開發者ID:tomgallard,項目名稱:pwinty-dotnet,代碼行數:17,代碼來源:PaymentTest.cs

示例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);
//.........這裏部分代碼省略.........
開發者ID:ekostadinov,項目名稱:MyProjects,代碼行數:101,代碼來源:TestGoogleCalendar.cs

示例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");
        }
開發者ID:null2014,項目名稱:SeleniumTest,代碼行數:19,代碼來源:Others.cs

示例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]); //回到主窗口
 }
開發者ID:null2014,項目名稱:SeleniumTest,代碼行數:15,代碼來源:Others.cs

示例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]);
 }
開發者ID:null2014,項目名稱:SeleniumTest,代碼行數:10,代碼來源:Others.cs


注:本文中的OpenQA.Selenium.Firefox.FirefoxDriver.SwitchTo方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。