当前位置: 首页>>代码示例>>C#>>正文


C# IWebDriver.SwitchTo方法代码示例

本文整理汇总了C#中IWebDriver.SwitchTo方法的典型用法代码示例。如果您正苦于以下问题:C# IWebDriver.SwitchTo方法的具体用法?C# IWebDriver.SwitchTo怎么用?C# IWebDriver.SwitchTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IWebDriver的用法示例。


在下文中一共展示了IWebDriver.SwitchTo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WhereIsMyCheese

        public void WhereIsMyCheese(string url)
        {
            try
            {
                _driver = Browser.GetFirefoxDriver();

                _driver.Navigate().GoToUrl(url);

                _driver.FindElement(By.Id("windowOpener")).Click();

                _driver.SwitchTo().Window("windowName");
                _driver.FindElement(By.Id("CheesyButton")).Click();

                _driver.SwitchTo().Alert().Accept();
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("An exception occured: " + ex.Message);
                Debug.WriteLine("An exception occured: " + ex.Message);
            }
            finally
            {
                _driver.Quit();
            }
        }
开发者ID:BobLokerse,项目名称:SeleniumCoding,代码行数:25,代码来源:CheeseLocator.cs

示例2: Dsecure

        public void Dsecure(IWebDriver driver)
        {
            if (IsElementPresent(driver, By.TagName("iframe")))
            {
                var frameElement = driver.FindElement(By.TagName("iframe"));
                driver.SwitchTo().Frame(frameElement);
                driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
                Thread.Sleep(0x1388);
                driver.SwitchTo().Alert().Accept();

                var location = driver.Url;
                if (location.Contains("3DSecureState=Success"))
                {
                    _datarow.Newrow("3D secure", location, "3DSecureState=Success", "PASS", driver);
                    driver.FindElement(By.LinkText("start again")).Click();
                }
                else if (location.Contains("State=Declined"))
                {
                    _datarow.Newrow("3D secure", location, "3D secure Declined", "FAIL", driver);
                    driver.FindElement(By.LinkText("start again")).Click();
                }
            }
            else
            {
                var actual = driver.Url;
                _datarow.Newrow("Checkout", "Server Error", actual, "FAIL", driver);
                new Screenshot().Screenshotfailed(driver);
                driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
            }
        }
开发者ID:TejaVellanki,项目名称:PlatformAutomationTestFramework,代码行数:30,代码来源:MopayBackup.cs

示例3: SelectBlankWindow

        /**
         * Selects the only <code>_blank</code> window. A window open with
         * <code>target='_blank'</code> will have a <code>window.name = null</code>.
         * <p/>
         * <p>This method assumes that there will only be one single
         * <code>_blank</code> window and selects the first one with no name.
         * Therefore if for any reasons there are multiple windows with
         * <code>window.name = null</code> the first found one will be selected.
         * <p/>
         * <p>If none of the windows have <code>window.name = null</code> the last
         * selected one will be re-selected and a {@link SeleniumException} will
         * be thrown.
         *
         * @throws NoSuchWindowException if no window with
         *                               <code>window.name = null</code> is found.
         */
        public void SelectBlankWindow(IWebDriver driver)
        {
            string current = driver.GetWindowHandle();

            // Find the first window without a "name" attribute
            ReadOnlyCollection<string> handles = driver.GetWindowHandles();
            foreach (string handle in handles)
            {
                // the original window will never be a _blank window, so don't even look at it
                // this is also important to skip, because the original/root window won't have
                // a name either, so if we didn't know better we might think it's a _blank popup!
                if (handle == originalWindowHandle)
                {
                    continue;
                }

                driver.SwitchTo().Window(handle);
                string value = ((IJavaScriptExecutor)driver).ExecuteScript("return window.name;").ToString();
                if (string.IsNullOrEmpty(value))
                {
                    // We found it!
                    return;
                }
            }

            // We couldn't find it
            driver.SwitchTo().Window(current);
            throw new SeleniumException("Unable to select window _blank");
        }
开发者ID:hugs,项目名称:selenium,代码行数:45,代码来源:WindowSelector.cs

示例4: ChromeTest

        public void ChromeTest()
        {
            driver = new ChromeDriver();
            driver.Navigate().GoToUrl("");

            Func<string, IWebDriver> selectChildFrame = (x) => driver.SwitchTo().Frame(driver.FindElement(By.XPath(x)));
            Action<string> click = (string x) => driver.FindElement(By.XPath(x)).Click();
            Action<string> fElement = (string x) => driver.FindElement(By.XPath(x));
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));

            //Step into Main Frame

            selectChildFrame.Invoke("//frame[contains(@name, 'mainWindow')]");

            //Click into parts tab

            click.Invoke("//td[contains(@id, 'Tab1')]");

            //step into search part frame and search for a part containing '2008'

            selectChildFrame.Invoke("//iframe[contains(@name, 'iframeSearchPart')]");
            click.Invoke("//input[contains(@name, 'partName')]");
            driver.FindElement(By.XPath("//input[contains(@name, 'partName')]")).SendKeys("2008");
            click.Invoke("//input[contains(@value, 'Search')]");

            //step into iframePTSrchResults and click part of 777D12008

            selectChildFrame.Invoke("//iframe[contains(@id, 'iframePTSrchResults')]");
            selectChildFrame.Invoke("//frame[contains(@name, 'PartSearchResults')]");
            click.Invoke("//td[contains(text(), '777D12008')]");
            driver.SwitchTo().ParentFrame();
            selectChildFrame.Invoke("//frame[contains(@name, 'PartSearchDetails')]");
            click.Invoke("//span[contains(text(), '11A-544B004 (2009)-->Label Map MTD Gold')]");

            //view super session and add to pick list

            driver.SwitchTo().DefaultContent();
            selectChildFrame.Invoke("//frame[contains(@name, 'mainWindow')]");
            selectChildFrame.Invoke("//iframe[contains(@id, 'iframeSearchModel')]");
            selectChildFrame.Invoke("//iframe[contains(@id, 'iframeMDSrchResults')]");
            selectChildFrame.Invoke("//frame[contains(@name, 'ModelSearchDetails')]");
            selectChildFrame.Invoke("//frame[contains(@name, 'IPL1361227DATA')]");
            driver.FindElement(By.XPath("//tr[contains(@id, '777S30145')]")).FindElement(By.XPath("//tr/td/a")).Click();
            driver.FindElement(By.XPath("//tr[contains(@id, '777S30145')]")).FindElement(By.XPath("//a[contains(@href, 'addToPicklist')]")).Click();

            //navigate to model
            driver.SwitchTo().DefaultContent();
            selectChildFrame.Invoke("//frame[contains(@name, 'mainWindow')]");
            click.Invoke("//td[contains(@id, 'Tab0')]");

            //search a model of 2007 in MTD2014

            selectChildFrame.Invoke("//iframe[contains(@id, 'iframeSearchModel')]");
            driver.FindElement(By.XPath("//td[contains(@class, 'oemDropDownContainer')]")).FindElement(By.XPath("//td/select")).Click();
            driver.FindElement(By.XPath("//option[contains(@value, '5010')]")).Click();
            click.Invoke("//input[contains(@name, 'modelName')]");
            driver.FindElement(By.XPath("//input[contains(@name, 'modelName')]")).SendKeys("2007");
            click.Invoke("//input[contains(@value, 'Search')]");
        }
开发者ID:cayala,项目名称:Portfolio,代码行数:59,代码来源:Selenium.cs

示例5: WaitForPageToLoad

        public static bool WaitForPageToLoad(IWebDriver driver, int timeOutInSeconds)
        {
            string state = string.Empty;
            try
            {
                WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(timeOutInSeconds));

                //Checks every 500 ms whether predicate returns true if returns exit otherwise keep trying till it returns ture
                wait.Until(d =>
                {

                    try
                    {
                        state = ((IJavaScriptExecutor)driver).ExecuteScript(@"return document.readyState").ToString();
                    }
                    catch (InvalidOperationException)
                    {
                        //Ignore
                    }
                    catch (NoSuchWindowException)
                    {
                        //when popup is closed, switch to last windows
                        driver.SwitchTo().Window(driver.WindowHandles.Last());
                    }
                    //In IE7 there are chances we may get state as loaded instead of complete
                    return (state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) ||
                            state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase));

                });
            }
            catch (TimeoutException)
            {
                //sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls
                if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase))
                    throw;
            }
            catch (NullReferenceException)
            {
                //sometimes Page remains in Interactive mode and never becomes Complete, then we can still try to access the controls
                if (!state.Equals("interactive", StringComparison.InvariantCultureIgnoreCase))
                    throw;
            }
            catch (WebDriverException)
            {
                if (driver.WindowHandles.Count == 1)
                {
                    driver.SwitchTo().Window(driver.WindowHandles[0]);
                }
                state = ((IJavaScriptExecutor)driver).ExecuteScript(@"return document.readyState").ToString();
                if (
                    !(state.Equals("complete", StringComparison.InvariantCultureIgnoreCase) ||
                      state.Equals("loaded", StringComparison.InvariantCultureIgnoreCase)))
                    throw;
            }
            return true;
        }
开发者ID:Jac21,项目名称:GistsCollection,代码行数:56,代码来源:SeleniumApi.cs

示例6: CheckboxTest

        private static void CheckboxTest(IWebDriver driver)
        {
            driver.Url = "http://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_checkbox_get";
            IWebElement rightFrame = driver.FindElement(By.Id("iframeResult"));
            driver.SwitchTo().Frame(rightFrame);

            var checkbox = driver.FindElement(By.Id("myCheck"));
            if (!checkbox.Selected)
                checkbox.Click();
            driver.SwitchTo().DefaultContent();
        }
开发者ID:jiangsheng,项目名称:Samples,代码行数:11,代码来源:Program.cs

示例7: TenancySearchPage

        public TenancySearchPage(IWebDriver driver)
            : base(driver, TenancySearchPage.FRAME)
        {
            WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
            wait.Until((d) => { return d.Title.Contains(pageTitle); });

            //Switch to main frame when it is visible
            driver.SwitchTo().DefaultContent();
            wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitsec));
            IWebElement f1 = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(FRAME)));
            driver.SwitchTo().Frame(f1);
        }
开发者ID:pjagga,项目名称:SeleniumMSTestVS2013,代码行数:12,代码来源:TenancySearchPage.cs

示例8: HasFocus

        public static bool HasFocus(this IWebElement element, IWebDriver driver)
        {
            if (element.GetType() == typeof (RemoteWebElement))
            {
                return driver.SwitchTo().ActiveElement().Equals(element);
            }

            if (element.GetType() == typeof (WebElement))
            {
                WebElement wElement = element as WebElement;
                return wElement != null && driver.SwitchTo().ActiveElement().Equals(wElement.InnerElement);
            }
            return false;
        }
开发者ID:chandramouleswaran,项目名称:Hypertest,代码行数:14,代码来源:WebDriverExtensions.cs

示例9: HandleSeleneseCommand

        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="driver">The driver used to execute the command.</param>
        /// <param name="locator">The first parameter to the command.</param>
        /// <param name="value">The second parameter to the command.</param>
        /// <returns>The result of the command.</returns>
        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            string current = driver.CurrentWindowHandle;

            List<string> attributes = new List<string>();
            foreach (string handle in driver.WindowHandles)
            {
                driver.SwitchTo().Window(handle);
                attributes.Add(driver.Title);
            }

            driver.SwitchTo().Window(current);

            return attributes.ToArray();
        }
开发者ID:draculavlad,项目名称:selenium,代码行数:22,代码来源:GetAllWindowTitles.cs

示例10: Dsecure

 public void Dsecure(IWebDriver driver)
 {
     var frameElement = driver.FindElement(By.TagName("iframe"));
     driver.SwitchTo().Frame(frameElement);
     driver.FindElement(By.CssSelector("input[type=\"submit\"]")).Click();
     Thread.Sleep(0x1388);
     Thread.Sleep(0x1f40);
     var location = driver.Url;
     if (location.Contains("3DSecureState=Success"))
     {
         _datarow.Newrow("3D secure", location, "3DSecureState=Success", "PASS", driver);
         if (IsElementPresent(driver, By.LinkText("start again")))
         {
             driver.FindElement(By.LinkText("start again")).Click();
         }
         else
         {
             driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
         }
     }
     else
     {
         _datarow.Newrow("3D secure", location, "3D secure Declined", "FAIL", driver);
         if (IsElementPresent(driver, By.LinkText("start again")))
         {
             driver.FindElement(By.LinkText("start again")).Click();
         }
         else
         {
             driver.Navigate().GoToUrl("http://devpaytest.mobankdev.com/");
         }
     }
 }
开发者ID:TejaVellanki,项目名称:PlatformAutomationTestFramework,代码行数:33,代码来源:Mopay.cs

示例11: Socialmediashare

 public void Socialmediashare(IWebDriver driver, Datarow datarow)
 {
     driver.FindElement(By.XPath("//div[@id='social-media-sharing']/a[1]/img")).Click();
     driver.FindElement(By.XPath("//div[@id='social-media-sharing']/a[2]/img")).Click();
     driver.FindElement(By.XPath("//div[@id='social-media-sharing']/a[3]/img")).Click();
     var str = driver.WindowHandles.GetEnumerator();
     var parentwindow = driver.CurrentWindowHandle;
     while (str.MoveNext())
     {
         var window = Convert.ToString(str.Current);
         driver.SwitchTo().Window(window);
         var url = driver.Url;
         datarow.Newrow("Social Share URL", "", url, "PASS");
     }
     driver.SwitchTo().Window(parentwindow);
 }
开发者ID:TejaVellanki,项目名称:PlatformAutomationTestFramework,代码行数:16,代码来源:SocialMediaSharing.cs

示例12: RefreshPage

 public static void RefreshPage(IWebDriver driver, string frame, string childFrame = null)
 {
     //Switch to main frame when it is visible
     driver.SwitchTo().DefaultContent();
     WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(waitsec));
     IWebElement f1 = wait.Until(ExpectedConditions.ElementIsVisible(By.Id(frame)));
     if (childFrame != null)
     {
         driver.SwitchTo().Frame(f1);
         driver.SwitchTo().Frame(childFrame);
     }
     else
     {
         driver.SwitchTo().Frame(f1);
     }
 }
开发者ID:pjagga,项目名称:SeleniumMSTestVS2013,代码行数:16,代码来源:RefreshPageFrame.cs

示例13: HandleSeleneseCommand

        /// <summary>
        /// Handles the command.
        /// </summary>
        /// <param name="driver">The driver used to execute the command.</param>
        /// <param name="locator">The first parameter to the command.</param>
        /// <param name="value">The second parameter to the command.</param>
        /// <returns>The result of the command.</returns>
        protected override object HandleSeleneseCommand(IWebDriver driver, string locator, string value)
        {
            string current = driver.CurrentWindowHandle;

            List<string> attributes = new List<string>();
            foreach (string handle in driver.WindowHandles)
            {
                driver.SwitchTo().Window(handle);
                string attributeValue = (string)((IJavaScriptExecutor)driver).ExecuteScript("return '' + window[arguments[0]];", value);
                attributes.Add(attributeValue);
            }

            driver.SwitchTo().Window(current);

            return attributes.ToArray();
        }
开发者ID:draculavlad,项目名称:selenium,代码行数:23,代码来源:GetAttributeFromAllWindows.cs

示例14: DeleteFirstUser

        public static void DeleteFirstUser(IWebDriver driver)
        {
            Login.AsHost(driver);

            driver.Navigate().GoToUrl(UserAccountsPage);

            driver.WaitClick(AccountManagerDeleteButton);

            driver.SwitchTo().Alert().Accept();
            driver.SwitchTo().DefaultContent();

            driver.WaitClick(AccountManagerRemoveButton);

            driver.SwitchTo().Alert().Accept();
            driver.SwitchTo().DefaultContent();
        }
开发者ID:ryanmalone,项目名称:BGDNNWEB,代码行数:16,代码来源:UserAccounts.cs

示例15: AcceptAlert

 private void AcceptAlert(IWebDriver browser)
 {
     var alertText = "";
     int loop = 2;
     IAlert alert = null;
     while (alertText.Equals("") && loop > 0)
     {
         if (alert == null)
         {
             try
             {
                 alert = browser.SwitchTo().Alert();
             }
             catch
             { System.Threading.Thread.Sleep(50); }
         }
         else
         {
             try
             {
                 alert.Accept();
                 alertText = alert.Text;
             }
             catch (Exception ex)
             {
                 if (ex.Message.Equals("No alert is present")) alertText = "Already Accepted";
                 else System.Threading.Thread.Sleep(50);
             }
         }
         loop--;
     }
 }
开发者ID:rainymaple,项目名称:WebTester,代码行数:32,代码来源:AlertAccept.cs


注:本文中的IWebDriver.SwitchTo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。