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


C# ChromeDriver.SwitchTo方法代码示例

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


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

示例1: ZoomModel

        public ZoomModel(string username, string password, BackgroundWorker bw, bool justZoom)
        {
            bool looping = true;
            while (looping)
            {

                    ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
                    service.HideCommandPromptWindow = true;

                    ChromeOptions options = new ChromeOptions();
                    options.AddArgument("start-maximized");
                    options.AddArgument("user-data-dir=" + App.Folder + "profileZB");

                    IWebDriver driver = new ChromeDriver(service, options);
                    driver.Navigate().GoToUrl("http://members.grabpoints.com/#/login?email=" + username);

                    try
                    {
                        //driver.FindElement(By.Name("email")).SendKeys(username);
                        //driver.FindElement(By.Name("email")).SendKeys(Keys.Enter);
                        ////Helpers.wait(5000);
                        driver.FindElement(By.Id("password")).SendKeys(password);
                        driver.FindElement(By.ClassName("btn-block")).Click();
                    }
                    catch { }

                    Helpers.wait(10000);
                if (!justZoom)
                {

                    try
                    {
                        int counter = 0;
                        IList<IWebElement> turnOffNotifcations = driver.FindElements(By.ClassName("btn-block"));
                        foreach (IWebElement turnOffNotication in turnOffNotifcations)
                        {
                            if (counter == turnOffNotifcations.Count - 1)
                            {
                                turnOffNotication.Click();
                            }
                            counter++;
                        }
                    }
                    catch { }

                    int hr = DateTime.Now.Hour;

                    try
                    {
                        driver.Navigate().GoToUrl("http://members.grabpoints.com/#/offers/watch_videos");
                    }
                    catch { }

                    while (!viroolBool)
                    {
                        try
                        {
                            System.Collections.ObjectModel.ReadOnlyCollection<string> windowHandles = driver.WindowHandles;

                            foreach (String window in windowHandles)
                            {
                                try
                                {
                                    IWebDriver popup = driver.SwitchTo().Window(window);
                                }
                                catch { }

                                try
                                {
                                    if (driver.Title.Contains("Facebook"))
                                    {
                                        driver.Close();
                                    }
                                }
                                catch { }

                                try
                                {
                                    IList<IWebElement> surveys = driver.FindElements(By.ClassName("btn-block"));
                                    if (surveys.Count > 2)
                                    {
                                        driver.FindElement(By.ClassName("btn-block")).Click();
                                    }
                                }
                                catch { }

                                if (!junVideos)
                                    junVids(driver);
                                if (!volume)
                                    volume11(driver);
                                if (volume && junVideos && !viroolBool)
                                    virool(driver);
                                Helpers.wait(5000);
                            }
                        }
                        catch { }
                    }

                    Helpers.closeWindows(driver, titles);
                    driver.Close();
//.........这里部分代码省略.........
开发者ID:XelGar256,项目名称:Scrap,代码行数:101,代码来源:ZoomModel.cs

示例2: Main

        private static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver("C:\\");
            driver.Navigate().GoToUrl("file:///C:/Users/anil.krishnamaneni/Desktop/New%20Text%20Document.html");

            var coll = driver.FindElements(By.TagName("label"));
            foreach (var label in coll)
            {
                if (label.Text.Trim() == "welcome to Ding")
                {
                    label.Click();
                    break;
                }
            }

            var alert = driver.WaitGetAlert();

            IAlert a = driver.SwitchTo().Alert();
            a.Accept();

            driver.FindElement(By.TagName("Input")).Click();
            a = driver.SwitchTo().Alert();
            a.Accept();
            driver.FindElement(By.ClassName("submit")).Click();
            a = driver.SwitchTo().Alert();
            a.Accept();
        }
开发者ID:krishnamanenianil,项目名称:Selenium,代码行数:27,代码来源:Program.cs

示例3: Browse

        public static void Browse(string username, Action<SouthwindBrowser> action)
        {
            var selenium = new ChromeDriver();

            var browser = new SouthwindBrowser(selenium);
            try
            {
                browser.Login(username, username);
                action(browser);
            }
            catch (UnhandledAlertException)
            {
                selenium.SwitchTo().Alert();

            }
            finally
            {
                selenium.Close();
            }
        }
开发者ID:signumsoftware,项目名称:southwind,代码行数:20,代码来源:Common.cs

示例4: NaverCrawler

        public NaverCrawler()
        {
            string id = ConfigurationManager.AppSettings["id"];
            string password = ConfigurationManager.AppSettings["password"];
            var processList = Process.GetProcessesByName("chromedriver");
            foreach( var process in processList )
            {
                process.Kill();
            }

            var chromeDriverService = ChromeDriverService.CreateDefaultService();
            chromeDriverService.HideCommandPromptWindow = true;

            var option = new ChromeOptions();
            option.AddExtension("3.7_0.crx");
            driver = new ChromeDriver(chromeDriverService, option );

            while (driver.WindowHandles.Count < 2)
            {
                Thread.Sleep(100);
            }

            driver.SwitchTo().Window(driver.WindowHandles[1]);

            WebDriverWait _wait = new WebDriverWait(driver, new TimeSpan(0, 1, 0));

            driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 10));

            _wait.Until(d => d.FindElement(By.Id("user_email")));
            driver.FindElementById("user_email").SendKeys(String.Format("{0}@naver.com\n", id));
            _wait.Until(d => d.FindElement(By.Id("user_password")));
            driver.FindElementById("user_password").SendKeys(password);
            driver.FindElementById("loginbtn").Click();

            driver.SwitchTo().Window(driver.WindowHandles[0]);
            driver.Url = loginFormUrl;
            driver.FindElementByCssSelector("#id").SendKeys(id);
            driver.FindElementByCssSelector("#pw").SendKeys(password);

            driver.FindElementByCssSelector("input.int_jogin").Click();

            cookieContainer = new CookieContainer();
            ReadOnlyCollection<OpenQA.Selenium.Cookie> cookieCollections = null;

            bool sessionFound = false;
            while (!sessionFound)
            {
                cookieCollections = driver.Manage().Cookies.AllCookies;
                foreach( var cookie in cookieCollections )
                {
                    if ( cookie.Name == "JSESSIONID" )
                    {
                        sessionFound = true;
                        break;
                    }
                }
            }
            foreach( var cookie in cookieCollections )
            {
                cookieContainer.Add(new System.Net.Cookie(cookie.Name, cookie.Value, cookie.Path, cookie.Domain));
            }

            driver.Quit();
        }
开发者ID:hyunjong-lee,项目名称:Mastermind_bluehole,代码行数:64,代码来源:NaverCrawler.cs

示例5: Run

        static void Run(string[] args)
        {
            var chromeDriverPath = string.Concat(AppDomain.CurrentDomain.BaseDirectory, "driver");
            bool enableCustomJustification = false;

            string urlLogin = ConfigurationManager.AppSettings[CONFIG_PONTO_LOGIN_URL];
            if (string.IsNullOrEmpty(urlLogin))
                throw new InvalidOperationException(string.Format("Url de login do sistema de ponto não definida! Verifique a chave \"{0}\" no app.config.", CONFIG_PONTO_LOGIN_URL));

            string username = ConfigurationManager.AppSettings[CONFIG_USERNAME];
            if (string.IsNullOrEmpty(username))
                throw new InvalidOperationException(string.Format("Nome de usuário não configurado! Verifique a chave \"{0}\" no app.config.", CONFIG_USERNAME));

            string password = ConfigurationManager.AppSettings[CONFIG_PASSWORD];
            if (string.IsNullOrEmpty(password))
                throw new InvalidOperationException(string.Format("Senha de usuário não configurada! Verifique a chave \"{0}\" no app.config.", CONFIG_PASSWORD));

            if (!bool.TryParse(ConfigurationManager.AppSettings[CONFIG_ENABLE_JUSTIFICATION], out enableCustomJustification))
                enableCustomJustification = false;

            string inputApontamento = string.Empty;

            if (args == null || !args.Any())
            {
                Console.WriteLine("Informe o apontamento:  1-Entrada. 2-Início almoço. 3-Volta Almoço. 4-Saída.");
                inputApontamento = Console.ReadLine();
            }
            else
            {
                inputApontamento = args[0];
            }

            Console.WriteLine("");

            int apontamento = 0;
            if (!int.TryParse(inputApontamento, out apontamento))
                throw new InvalidOperationException(string.Format("Apontamento não definido corretamente. Valor informado: \"{0}\"! Utilize:  1-Entrada.  2-Início almoço.  3-Volta Almoço.  4-Saída.", inputApontamento));

            using (var driver = new ChromeDriver(chromeDriverPath))
            {
                driver.Navigate().GoToUrl(urlLogin);

                var usernameField = driver.FindElementById("ctl00_m_g_1f2f91c5_726b_47c3_a64d_34117653e0e4_ctl00_signInControl_UserName");
                var passwordField = driver.FindElementById("ctl00_m_g_1f2f91c5_726b_47c3_a64d_34117653e0e4_ctl00_signInControl_Password");
                var buttonLogin = driver.FindElementById("ctl00_m_g_1f2f91c5_726b_47c3_a64d_34117653e0e4_ctl00_signInControl_LoginButton");

                usernameField.Clear();
                usernameField.SendKeys(username);

                passwordField.Clear();
                passwordField.SendKeys(password);

                buttonLogin.Click();

                IWait<IWebDriver> firstWait = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
                firstWait.Until(x => driver.FindElementById("entrada") != null);

                string btnApontamentoId = string.Empty;

                switch ((Apontamento)apontamento)
                {
                    case Apontamento.ENTRADA:
                        btnApontamentoId = "entrada";
                        break;

                    case Apontamento.INICIO_ALMOCO:
                        btnApontamentoId = "inicioAlmoco";
                        break;

                    case Apontamento.VOLTA_ALMOCO:
                        btnApontamentoId = "voltaAlmoco";
                        break;

                    case Apontamento.SAIDA:
                        btnApontamentoId = "saida";
                        break;
                }

                var btnApontamento = driver.FindElementById(btnApontamentoId);
                btnApontamento.Click();

                IWait<IWebDriver> secondWait = new WebDriverWait(driver, TimeSpan.FromSeconds(90));
                secondWait.Until(x => driver.FindElementById("entrada") != null);

                if ((Apontamento)apontamento == Apontamento.SAIDA)
                {
                    try
                    {
                        driver.SwitchTo().DefaultContent();

                        var dialogIFrame = driver.FindElement(By.Id(""));
                        driver.SwitchTo().Frame(dialogIFrame);

                        var textAreaJustificativa = driver.FindElement(By.Id("ctl00_m_g_cac22e8d_9ad5_4163_b85d_7254c3524eac_ctl00_txtJustificativa"));
                        var btnConfirmarJustificativa = driver.FindElement(By.Id("ctl00_m_g_cac22e8d_9ad5_4163_b85d_7254c3524eac_ctl00_btnSalvar"));

                        string justificativa = ".";

                        if (enableCustomJustification)
                        {
//.........这里部分代码省略.........
开发者ID:vitorsalgado,项目名称:crap,代码行数:101,代码来源:Program.cs

示例6: Main

        static int Main(string[] args)
        {
            bool testDashboardOnly = false;
            if (testDashboardOnly)
            {
                // FIRST RUN: this requests access to ports
                Fiddler.FiddlerApplication.Startup(8877, Fiddler.FiddlerCoreStartupFlags.Default);

                var trafficSeesionItems = new List<Fiddler.Session>();
                Fiddler.FiddlerApplication.AfterSessionComplete += delegate(Fiddler.Session session)
                {
                    trafficSeesionItems.Add(session);
                };

                // FIXME: would be nice to load a local dashboard, but if we open file:/// it will NOT generate HTTP traffic, how to log it then?
                string baseUrl = "http://zsolt-ws.isis.vanderbilt.edu/META/dashboards/36cfgs4tbs/";

                var options = new ChromeOptions();

                options.AddArgument("--allow-file-access-from-files");
                options.AddArgument("--start-maximized");
                //options.AddArgument("--enable-experimental-extension-apis");

                // FIRST RUN: this requests access to ports
                IWebDriver driver = new ChromeDriver(@"..\..\..\..\3rdParty\chromedriver", options);
                driver.Navigate().GoToUrl(baseUrl);

                driver.SwitchTo().Frame(driver.FindElement(By.TagName("iframe")));

                ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;

                while (true) // Handle timeout somewhere
                {
                    var ajaxIsComplete = (bool)(driver as IJavaScriptExecutor).ExecuteScript("return jQuery.active == 0");
                    if (ajaxIsComplete)
                        break;
                    System.Threading.Thread.Sleep(100);
                }


                var dataLoad = driver.FindElement(By.CssSelector("[id='dataLoadInProgress']"));
                var i = 0;
                while (dataLoad.Displayed && dataLoad.Enabled && i < 10)
                {
                    System.Threading.Thread.Sleep(1000);
                    i++;
                }

                if (i > 10)
                {
                    return 0;
                }

                Screenshot screenshot = screenshotDriver.GetScreenshot();
                screenshot.SaveAsFile("0.__main_page.png", System.Drawing.Imaging.ImageFormat.Png);

                var maintab = driver.FindElement(By.CssSelector("[id='mainTabs']"));
                var elements = maintab.FindElements(By.XPath("//a[@vf-page]"));

                var pageCounter = 1;

                foreach (var element in elements.ToList())
                {
                    bool visible = element.Displayed && element.Enabled;
                    if (visible)
                    {
                        element.Click();
                        element.SendKeys(OpenQA.Selenium.Keys.Escape);
                        System.Threading.Thread.Sleep(1000);

                        screenshot = screenshotDriver.GetScreenshot();
                        screenshot.SaveAsFile(pageCounter.ToString() + element.GetAttribute("vf-page").Replace("/", "_") + "_page.png", System.Drawing.Imaging.ImageFormat.Png);
                        pageCounter++;

                    }
                }

                foreach (var trafficSeesionItem in trafficSeesionItems.ToList())
                {
                    // HINT: this will log all HTTP traffic no matter which application generates.
                    System.Diagnostics.Trace.WriteLine(String.Format("{0} {1}", trafficSeesionItem.responseCode, trafficSeesionItem.fullUrl));
                }

                driver.Quit();

                Fiddler.FiddlerApplication.oProxy.Detach();

                return 0;
            }

            int ret = Xunit.ConsoleClient.Program.Main(new string[] {
                Assembly.GetAssembly(typeof(Test)).CodeBase.Substring("file:///".Length),
                //"/noshadow",
            });
            Console.In.ReadLine();
            return ret;
        }
开发者ID:neemask,项目名称:meta-core,代码行数:97,代码来源:DynamicsTeamTest.cs

示例7: CheckParkCostandTimeCase2

        public void CheckParkCostandTimeCase2()
        {
            IWebDriver Driver = new ChromeDriver(@"C:\Users\Rebecca\Documents\Visual Studio 2015\Chrome Driver");

            Driver.Navigate().GoToUrl("http://adam.goucher.ca/parkcalc/index.php");
            Thread.Sleep(2000);

            //Get current window handle so we can switch when clicking the calendar icon
            String OriginalHandle = Driver.CurrentWindowHandle;

            // Select Long Term Surface Parking from Lot drop down menu
            SelectElement Lot = new SelectElement(Driver.FindElement(By.Id("Lot")));
            Lot.SelectByValue("LTS");

            //Click calendar icon to enter entry date
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[2]/td[2]/font/a/img")).Click();
            Thread.Sleep(2000);

            //Switch Driver to new calendar frame for entry date
            string EntryDateHandle = string.Empty;
            ReadOnlyCollection<string> EntryWindowHandles = Driver.WindowHandles;

            foreach (string Handle in EntryWindowHandles)
            {
                if (Handle != OriginalHandle)
                {
                    EntryDateHandle = Handle; break;
                }
            }

            Driver.SwitchTo().Window(EntryDateHandle);


            //Click the year descend button twice to get the year to be 2014 for entry date, click 1 for 01/01/2014
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[1]/td/table/tbody/tr/td[2]/a[1]")).Click();
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[1]/td/table/tbody/tr/td[2]/a[1]")).Click();


            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[4]/font/a")).Click();

            //Switch back to old frame to click calendar icon for exit date
            Driver.SwitchTo().Window(OriginalHandle);

            //Click calendar icon to enter exit date
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[3]/td[2]/font/a/img")).Click();
            Thread.Sleep(2000);

            string ExitDateHandle = string.Empty;
            ReadOnlyCollection<string> ExitWindowHandles = Driver.WindowHandles;

            foreach (string Handle in ExitWindowHandles)
            {
                if (Handle != OriginalHandle)
                {
                    ExitDateHandle = Handle; break;
                }
            }

            Driver.SwitchTo().Window(ExitDateHandle);

            //Click the year descend button twice to get the year to be 2014 for exit date, click on the 1st to get 02/01/2014 for exit date
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[1]/td/table/tbody/tr/td[2]/a[1]")).Click();
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[1]/td/table/tbody/tr/td[2]/a[1]")).Click();

            SelectElement ExitMonth = new SelectElement(Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[1]/td/table/tbody/tr/td[1]/select")));
            ExitMonth.SelectByText("February");

            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[7]/font/a")).Click();

            //Switch back to original frame in order to click the calculate button
            Driver.SwitchTo().Window(OriginalHandle);

            //Click calculate button
            Driver.FindElement(By.XPath("/html/body/form/input[2]")).Click();
            Thread.Sleep(2000);

            //Check cost is equal to $ 270.00
            try
            {
                Assert.AreEqual("$ 270.00", Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[2]/span[1]/font/b")).Text);
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }

            //Check duration of stay is (0 Days, 1 Hours, 0 Minutes)
            try
            {
                Assert.AreEqual("(31 Days, 0 Hours, 0 Minutes)", Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[2]/span[2]/font/b")).Text.Trim());
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }
            

            // Quit Chrome
//.........这里部分代码省略.........
开发者ID:rsweaver,项目名称:Mindbody-Interview-Assignment-,代码行数:101,代码来源:UnitTest1.cs

示例8: CheckParkCostandTimeCase7

        public void CheckParkCostandTimeCase7()
        {
            IWebDriver Driver = new ChromeDriver(@"C:\Users\Rebecca\Documents\Visual Studio 2015\Chrome Driver");

            Driver.Navigate().GoToUrl("http://adam.goucher.ca/parkcalc/index.php");
            Thread.Sleep(2000);

            String OriginalHandle = Driver.CurrentWindowHandle;

            // Select Long Term Surface Parking from Lot drop down menu
            SelectElement Lot = new SelectElement(Driver.FindElement(By.Id("Lot")));
            Lot.SelectByValue("LTS");

            // Enter 4:00 PM in Entry Time, select PM in radio button
            Driver.FindElement(By.Id("EntryTime")).Clear();
            Driver.FindElement(By.Id("EntryTime")).SendKeys("4:00");

            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[2]/td[2]/font/input[3]")).Click();

            //Click calendar icon to enter entry date
            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[2]/td[2]/font/a/img")).Click();
            Thread.Sleep(2000);

            //Switch Driver to new calendar frame for entry date 01/02/2016
            string EntryDateHandle = string.Empty;
            ReadOnlyCollection<string> EntryWindowHandles = Driver.WindowHandles;

            foreach (string Handle in EntryWindowHandles)
            {
                if (Handle != OriginalHandle)
                {
                    EntryDateHandle = Handle; break;
                }
            }

            Driver.SwitchTo().Window(EntryDateHandle);

            Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[7]/font/a")).Click();

            Driver.SwitchTo().Window(OriginalHandle);

            //Check date is formatted correctly from calendar
            try
            {
                String DateValue = Driver.FindElement(By.Id("EntryDate")).GetAttribute("value");
                Assert.AreEqual("1/2/2016", DateValue);
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }

            // Enter 3:00 AM in Exit Time
            Driver.FindElement(By.Id("ExitTime")).Clear();
            Driver.FindElement(By.Id("ExitTime")).SendKeys("3:00");


            //Enter date as 01/07/2016 In Exit Date
            Driver.FindElement(By.Id("ExitDate")).Clear();
            Driver.FindElement(By.Id("ExitDate")).SendKeys("01/07/2016");

            //Click calculate button, Check cost is equal to $ 50.00, Check duration of stay is (4 Days, 11 Hours, 0 Minutes)
            Driver.FindElement(By.XPath("/html/body/form/input[2]")).Click();
            Thread.Sleep(2000);

            try
            {
                Assert.AreEqual("$ 50.00", Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[2]/span[1]/font/b")).Text);
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }

            try
            {
                Assert.AreEqual("(4 Days, 11 Hours, 0 Minutes)", Driver.FindElement(By.XPath("/html/body/form/table/tbody/tr[4]/td[2]/span[2]/font/b")).Text.Trim());
            }
            catch (Exception ex)
            {
                Driver.Quit();
                Assert.Fail();
            }

            // Quit Chrome
            Driver.Quit();
        }
开发者ID:rsweaver,项目名称:Mindbody-Interview-Assignment-,代码行数:89,代码来源:UnitTest1.cs

示例9: submit_registration_dialog_as_facebook_user

        private void submit_registration_dialog_as_facebook_user(ChromeDriver browser)
        {
            var windowContext = new WhichWindowContext(browser);

            click_registration_button(browser);

            browser.SwitchTo().Window(windowContext.GetNewWindowName());
            browser.FindElement(BySizzle.CssSelector("input[value=Continue]")).Click();

            browser.SwitchTo().Window(windowContext.GetOriginalWindowName());
        }
开发者ID:fschwiet,项目名称:FBDerp,代码行数:11,代码来源:User_can_register.cs

示例10: go_to_registration_form

        private void go_to_registration_form(ChromeDriver browser, IISExpressDriver site)
        {
            browser.Navigate().GoToUrl(site.UrlFor("/Account/Register"));

            var iframe =
                browser.WaitForElementEx(
                    BySizzle.CssSelector("iframe[src^=\"https://www.facebook.com/plugins/registration.php\"]"),
                    Constants.MSLongWait);

            browser.SwitchTo().Frame(iframe);
        }
开发者ID:fschwiet,项目名称:FBDerp,代码行数:11,代码来源:User_can_register.cs

示例11: CreateRental

        public void CreateRental(string file, string name)
        {
            var optionOne = new ChromeOptions();
                optionOne.AddArgument("test-type");
                IWebDriver driver = new ChromeDriver(optionOne);

                driver.Navigate().GoToUrl("https://dev-productadmin.vacationroost.com/"); // Dev

                //driver.Navigate().GoToUrl("https://productadmin.vacationroost.com");

                var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(250));

                //if (driver.FindElement(By.XPath("//*[@id='ctl00_body_ProductsTaskSelection_LodgingTasksGroup']/legend")).Displayed)
                //{
                //    Thread.Sleep(500);
                driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(145));
                IWebElement editSupplier = wait.Until(x => x.FindElement(By.XPath("//a[contains(.,'Edit a Lodging Supplier')]")));
                editSupplier.Click();
            //}

                string fileName = file;
                string suppName = name;

                IWebElement supplierName = wait.Until(x => x.FindElement(By.Id("ctl00_body_EntitySelection1_SupplierNameField")));
                supplierName.SendKeys(name);

                IWebElement supplierSearchButton = wait.Until(x => x.FindElement(By.Id("ctl00_body_EntitySelection1_EntitySelectionSearchButton")));
                supplierSearchButton.Click();

                IWebElement selectLinkForSupplier = wait.Until(x => x.FindElement(By.Id("ctl00_body_EntitySelection1_SupplierLodgingRepeater_ctl00_EditALodgingSupplierSelectionLineItem_SelectButton")));
                selectLinkForSupplier.Click();

                IWebElement createStandAloneRentalUnit = wait.Until(x => x.FindElement(By.Id("ctl00_body_DashboardControl1_TaskSelection_ctl01_RentalUnitTaskGroup_RentalUnitTasksControl_CreateRentalUnitSubTaskGroup_CreateARentalUnitTaskLink")));
                createStandAloneRentalUnit.Click();

                var rentalUnitInfos = new List<RentalUnitInformation>();
                var finalUrl = "";
                var finalComplex = "";

            if (File.Exists(fileName))
            {
                var xlApp = new Excel.Application();
                var xlWorkBook = xlApp.Workbooks.Open(file, false);
                var xlWorksheet = (Excel.Worksheet) xlWorkBook.Worksheets.Item[1];

                Excel.Range credentials = xlWorksheet.UsedRange;

                int rowCount = credentials.Rows.Count;

                try
                {
                    for (int i = 1; i < rowCount; i++)
                    {
                        string building = null;
                        string rooms = null;
                        string numberBath = null;
                        string numberGuess = null;

                        var complex = Convert.ToString(credentials.Cells[i + 1, 1].Value2);
                        var description = credentials.Cells[i + 1, 2].Value2.ToString();
                        building = credentials.Cells[i + 1, 3].Value2.ToString();
                        rooms = credentials.Cells[i + 1, 4].Value2.ToString();
                        var uNumber = credentials.Cells[i + 1, 5].Value2.ToString();
                        var uDescription = credentials.Cells[i + 1, 6].Value2.ToString();
                        numberBath = credentials.Cells[i + 1, 7].Value2.ToString();
                        numberGuess = credentials.Cells[i + 1, 8].Value2.ToString();

                        // Unit Name
                        var waiting = new WebDriverWait(driver, TimeSpan.FromSeconds(260));

                        IWebElement complexName =
                            waiting.Until(x => x.FindElement(By.Id("ctl00_body_InputForm_ComplexNameTextbox")));
                        complexName.SendKeys(complex);

                        // Complex Description

                        IWebElement iframe =
                            driver.FindElement(
                                By.XPath(
                                    "//*[@id='ctl00_body_InputForm_ComplexDescriptionLabel']/span[1]/div/div[2]/iframe"));
                        driver.SwitchTo().Frame(iframe);

                        IWebElement complexDescription = waiting.Until(x => x.FindElement(By.TagName("body")));

                        complexDescription.SendKeys(description);

                        driver.SwitchTo().DefaultContent();

                        // Building Type

                        switch (building)
                        {
                            case "Apartment":
                                IWebElement apartmentbuilding =
                                    waiting.Until(x => x.FindElement(By.Id("ctl00_body_InputForm_BuildingTypeList")));
                                var selectedApartment = new SelectElement(apartmentbuilding);
                                selectedApartment.SelectByText("Apartment");
                                break;

                            case "Bed and Breakfast":
//.........这里部分代码省略.........
开发者ID:majicas,项目名称:CreateRentalUnit,代码行数:101,代码来源:AddRentalUnits.cs

示例12: startWallBoard

        private void startWallBoard(object sender, RoutedEventArgs e)
        {
            // Configure the WebDriver path, and set to invisble (avoids annoying cmd prompt pop-up
            DriverService driverService = ChromeDriverService.CreateDefaultService(@".\WebDrivers\");
            driverService.HideCommandPromptWindow = true;

            // Use default chrome options for kiosk mode
            ChromeOptions cOptions = new ChromeOptions();
            //cOptions.AddArgument("--start-maximized --kiosk");
            //cOptions.BinaryLocation = "CHROME DIRECTORY";

            //IWebDriver driver = new ChromeDriver(@".\WebDrivers\");
            IWebDriver driver = new ChromeDriver(service: (ChromeDriverService)driverService, options: cOptions);

            //Create the actions builder
            Actions builder = new Actions(driver);

            //Default Site
            Thread.Sleep(100);
            Debug.Print(driver.CurrentWindowHandle);
            driver.SwitchTo().Window(driver.CurrentWindowHandle);
            Thread.Sleep(100);
            driver.Navigate().GoToUrl("http://www.reddit.com");
            Thread.Sleep(100);

            //Create some tabs
            driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
            Thread.Sleep(200);
            driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
            Thread.Sleep(200);
            driver.FindElement(By.CssSelector("body")).SendKeys(Keys.Control + "t");
            Thread.Sleep(200);

            //List the open tabs
            List<String> openTabs = openTabs = driver.WindowHandles.ToList<string>(); //driver.WindowHandles is a bloody read only collection
            foreach (var item in openTabs)
            {
                Debug.Print(item);
            }
            Debug.Print("TAB list size is  {0} ", openTabs.Count);

            Thread.Sleep(200);
            driver.SwitchTo().Window(openTabs[1]);
            Debug.Print("Switching to {0}", driver.Title);
            driver.Navigate().GoToUrl("http://www.facebook.com");
            Debug.Print("I am now to {0}", driver.Title);

            Thread.Sleep(200);
            driver.SwitchTo().Window(openTabs[2]);
            Debug.Print("Switching to {0}", driver.Title);
            driver.Navigate().GoToUrl("http://www.test.com");
            Debug.Print("I am now to {0}", driver.Title);

            Thread.Sleep(200);
            driver.SwitchTo().Window(openTabs[3]);
            Debug.Print("Switching to {0}", driver.Title);
            driver.Navigate().GoToUrl("http://www.baesystems.com");
            Debug.Print("I am now to {0}", driver.Title);

            Thread.Sleep(200);

            //Go to next tab (loop to first)
            Thread.Sleep(100);
            builder.SendKeys(Keys.Control + Keys.PageDown).Perform();
            driver.SwitchTo().Window(openTabs[0]);
            Thread.Sleep(100);
            driver.SwitchTo().ActiveElement();
            Debug.Print("BOLLOXX {0}", driver.Title);
            Thread.Sleep(100);

            //Hide the main app window
            this.frmMain.WindowState = System.Windows.WindowState.Minimized;
        }
开发者ID:RAGNOARAKNOS,项目名称:WallBoards,代码行数:73,代码来源:MainWindow.xaml.cs

示例13: GiftHulkModel

        public GiftHulkModel(string username, string password, BackgroundWorker bw, bool openHulk, int cards)
        {
            int chips = 0;

            ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
            service.HideCommandPromptWindow = true;

            ChromeOptions options = new ChromeOptions();
            options.AddArgument("start-maximized");
            options.AddArgument("user-data-dir=" + App.Folder + "profileGH");

            IWebDriver driver = new ChromeDriver(service, options);
            driver.Navigate().GoToUrl("http://www.gifthulk.com/");

            try
            {
                driver.FindElement(By.ClassName("signup-link")).Click();

                driver.FindElement(By.Name("log")).SendKeys(username);
                driver.FindElement(By.Name("pwd")).SendKeys(password);

                /*
                IList<IWebElement> iframes = driver.FindElements(By.TagName("iframe"));
                MessageBox.Show(iframes.Count.ToString());
                foreach(IWebElement iframe in iframes)
                {
                    MessageBox.Show(iframe.GetAttribute("title"));
                }
                */

                Helpers.switchFrameByNumber(driver, 3);
                //driver.FindElement(By.ClassName("recaptcha-checkbox")).Click();
                /*
                if (driver.FindElement(By.Id("recaptcha-anchor")).Displayed)
                {
                    MessageBox.Show("Hey");
                }
                */
                int classCount = 0;
                IList<IWebElement> ClassNames = driver.FindElements(By.TagName("div"));
                foreach(IWebElement ClassName in ClassNames)
                {
                    if (classCount == 4)
                    {
                        try
                        {
                            ClassName.Click();
                        }
                        catch { }
                    }
                    classCount++;
                }
                driver.SwitchTo().DefaultContent();
                while (driver.FindElement(By.Name("pwd")).Displayed)
                {

                }
                driver.FindElement(By.Name("pwd")).SendKeys(Keys.Enter);
            }
            catch { }
            finally { }
            Helpers.wait(5000);

            Helpers.ByClass(driver, "close-popup");

            if (!openHulk)
            {
                while (!bw.CancellationPending)
                {
                    int.TryParse(driver.FindElement(By.Id("daily_chips")).Text, out chips);

                    if (chips > 0)
                    {
                        driver.Navigate().GoToUrl("http://www.gifthulk.com/guess-the-card/");
                        GuessCard(driver, cards);
                    }

                    try
                    {
                        driver.FindElement(By.Id("watch-video")).Click();
                        sideVideos(driver);
                    }
                    catch { }

                    Helpers.wait(5000);
                    videosWatch(driver);
                }
            }
        }
开发者ID:XelGar256,项目名称:Scrap,代码行数:89,代码来源:GiftHulkModel.cs


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