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


C# Chrome.ChromeDriver类代码示例

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


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

示例1: Login

        public void Login(String loginUrl)
        {
            var options = new ChromeOptions();
            options.AddArguments("--test-type", "--start-maximized");
            options.AddArguments("--test-type", "--ignore-certificate-errors");
            options.BinaryLocation = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe";
            driver = new ChromeDriver("C:\\Program Files (x86)\\Google\\Chrome\\Application", options);

            driver.Navigate().GoToUrl(loginUrl);

            int timeout = 0;
            while (driver.FindElements(By.ClassName("logbox")).Count == 0 && timeout < 500)
            {
                Thread.Sleep(1);
                timeout++;

            }

            IWebElement element = driver.FindElement(By.ClassName("logbox"));

            IWebElement ElName = element.FindElement(By.Name("username"));
            ElName.Clear();
            ElName.SendKeys(loginName);
            IWebElement ElPassword = element.FindElement(By.Id("password"));
            ElPassword.Clear();
            ElPassword.SendKeys(loginPassword);
            IWebElement ElLogin = element.FindElement(By.Id("IBtnLogin"));
            ElLogin.Click();
        }
开发者ID:denisefan28,项目名称:Wind,代码行数:29,代码来源:UrlLabel.cs

示例2: TestHappyPathChrome

 public void TestHappyPathChrome()
 {
     ChromeOptions co = new ChromeOptions();
     co.AddArgument("--test-type");
     ChromeDriver cd = new ChromeDriver("C:\\Users\\ehelin\\Downloads\\chromedriver_win32", co);
     TestHappyPath(cd);
 }
开发者ID:ehelin,项目名称:TgimbaSeleniumTests,代码行数:7,代码来源:DesktopHappyPath.cs

示例3: StartDriver

		public static IWebDriver StartDriver (string browserType)
		{
			Trace.WriteLine("Start browser: '" + browserType + "'");

			IWebDriver driver = null;
			switch (browserType)
			{
				case "ie":
					{
						driver = new InternetExplorerDriver("Drivers");
						break;
					}
				case "firefox":
					{
						FirefoxProfile firefoxProfile = new FirefoxProfile();
						firefoxProfile.EnableNativeEvents = true;
						firefoxProfile.AcceptUntrustedCertificates = true;

						driver = new FirefoxDriver(firefoxProfile);
						break;
					}
				case "chrome":
					{
						ChromeOptions chromeOptions = new ChromeOptions();
						chromeOptions.AddArgument("--disable-keep-alive");

						driver = new ChromeDriver("Drivers", chromeOptions);
						break;
					}
			}

			driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));
			driver.Manage().Window.Maximize();
			return driver;
		}
开发者ID:rrsc,项目名称:Dnn.Platform,代码行数:35,代码来源:TestBase.cs

示例4: StartSession

        public void StartSession()
        {
            //Run selenium
            ChromeDriver cd = new ChromeDriver(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "lib"));
            cd.Url = @"https://login.yahoo.com/config/login?.src=fpctx&.intl=uk&.lang=en-GB&.done=https://uk.yahoo.com/%3fp=us";
            cd.Navigate();
            IWebElement e = cd.FindElementById("login-username");
            e.SendKeys("");
            e = cd.FindElementById("login-passwd");
            e.SendKeys("");
            e = cd.FindElementById("login-signin");
            e.Click();

            CookieContainer cc = new CookieContainer();
            //Get the cookies
            foreach (Cookie c in cd.Manage().Cookies.AllCookies)
            {
                string name = c.Name;
                string value = c.Value;
                cc.Add(new System.Net.Cookie(name, value, c.Path, c.Domain));
            }
            //cd.Quit();

            //Fire off the request
            HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("https://uk.finance.yahoo.com/portfolio/pf_15/view/dv");
            hwr.CookieContainer = cc;
            hwr.Method = "POST";
            hwr.ContentType = "application/x-www-form-urlencoded";
            StreamWriter swr = new StreamWriter(hwr.GetRequestStream());
            swr.Write("feeds=35");
            swr.Close();

            WebResponse wr = hwr.GetResponse();
            string s = new StreamReader(wr.GetResponseStream()).ReadToEnd();
        }
开发者ID:wongcharlie,项目名称:Acuity,代码行数:35,代码来源:YahooController.cs

示例5: 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

示例6: Register

        public static void Register(BackgroundWorker worker, string name, string password, IList<string> barcodes)
        {
            driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://7777.bg/user/lottery_tickets/register/");

            driver.FindElementByName("login_username").SendKeys(name);
            driver.FindElementByName("login_password").SendKeys(password);
            driver.FindElementByXPath("//input[@type='submit']").Click();

            Wait(driver);

            var barcodeTextBox = driver.FindElementByName("register_number");
            var submitButton = driver.FindElementByXPath("//button[@type='submit']");

            int progressPercentage = Convert.ToInt32(100 / barcodes.Count);

            for (int i = 0; i < barcodes.Count; i++)
            {
                barcodeTextBox.SendKeys(barcodes[i]);
                submitButton.Click();

                Thread.Sleep(1000);

                var finishButton = driver.FindElementByXPath("//a[@href='javascript:void(0);']");
                finishButton.Click();

                worker.ReportProgress(progressPercentage * (i + 1));
                Thread.Sleep(1000);
            }
        }
开发者ID:svstoichkov,项目名称:7777Registrator,代码行数:30,代码来源:ChromeRegistrator.cs

示例7: GetData

         //碳结圆钢价格行情
         public static void GetData(string linkName, int marketId)
         { 
             IWebDriver driver = new ChromeDriver();
             try
             {
                 driver.Manage().Window.Maximize();
                 driver.Navigate().GoToUrl("http://www.mysteel.com/");
                 var userName = driver.FindElement(By.Name("my_username"));
                 userName.SendKeys("tx6215");
                 var password = driver.FindElement(By.Name("my_password"));
                 password.SendKeys("tx6215");
                 userName.Submit();
                 var steel = driver.FindElement(By.LinkText("结构钢"));
                 driver.Navigate().GoToUrl(steel.GetAttribute("href"));
                 Thread.Sleep(2000);

                 var carbonRound = driver.FindElement(By.LinkText("碳圆"));
                 driver.Navigate().GoToUrl(carbonRound.GetAttribute("href"));
                 Thread.Sleep(2000);
                 var date = DateTime.Now.Day + "日";
                 GetPage(driver, linkName, marketId);
             }
             finally
             {
                 driver.Close();
                 driver.Quit();
             }
         }
开发者ID:jesusblessf6,项目名称:AutoPrice,代码行数:29,代码来源:CarbonRoundBase.cs

示例8: Host

        public Host()
        {
            // Hack
            int retryCount = 3;
            while (true)
            {
                try
                {
                    var options = new ChromeOptions();
                    options.AddArguments("test-type");

                    var service = ChromeDriverService.CreateDefaultService(@"..\..\Scaffolding\WebDriver");
                    service.HideCommandPromptWindow = false;
                    WebDriver = new ChromeDriver(service, options);
                    WebDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));

                    Page = new Page(WebDriver);
                    Page.GotoUrl("Home");
                    break;
                }
                catch
                {
                    if (retryCount-- == 0)
                        throw;
                }
            }
        }
开发者ID:j-kelly,项目名称:GalaxiaUniversity-Template,代码行数:27,代码来源:Host.cs

示例9: Can_Register_User

        public void Can_Register_User()
        {
            string chromeDriverDirectory = string.Format(@"{0}\..\..\..\tools", Directory.GetCurrentDirectory());

            IWebDriver driver = new ChromeDriver(chromeDriverDirectory);
            driver.Navigate().GoToUrl("http://localhost:64872/Account/Register");

            string username = string.Format("testuser{0}", DateTime.Now.Ticks);

            IWebElement userNameField = driver.FindElement(By.Id("UserName"));
            userNameField.SendKeys(username);

            IWebElement passwordField = driver.FindElement(By.Id("Password"));
            passwordField.SendKeys("[email protected]");

            IWebElement confirmPassword = driver.FindElement(By.Id("ConfirmPassword"));
            confirmPassword.SendKeys("[email protected]");

            IWebElement registerButton = driver.FindElement(By.ClassName("btn"));
            registerButton.Click();

            IWebElement loginName = driver.FindElement(By.LinkText(string.Format("Hello {0}!", username)));

            Assert.IsTrue(loginName.Displayed);

            driver.Quit();
        }
开发者ID:petekcchen,项目名称:blog,代码行数:27,代码来源:AccountTests.cs

示例10: Cannot_Register_User_With_Empty_Username

        public void Cannot_Register_User_With_Empty_Username()
        {
            string chromeDriverDirectory = string.Format(@"{0}\..\..\..\tools", Directory.GetCurrentDirectory());

            IWebDriver driver = new ChromeDriver(chromeDriverDirectory);
            driver.Navigate().GoToUrl("http://localhost:64872/Account/Register");

            IWebElement passwordField = driver.FindElement(By.Id("Password"));
            passwordField.SendKeys("[email protected]");

            IWebElement confirmPassword = driver.FindElement(By.Id("ConfirmPassword"));
            confirmPassword.SendKeys("[email protected]");

            IWebElement registerButton = driver.FindElement(By.ClassName("btn"));
            registerButton.Click();

            ReadOnlyCollection<IWebElement> errorMessages = driver.FindElements(By.XPath("//div[@class='validation-summary-errors']/ul/li"));

            IWebElement errorMessage = errorMessages.FirstOrDefault();

            Assert.IsNotNull(errorMessage);
            Assert.AreEqual("The User name field is required.", errorMessage.Text);

            driver.Quit();
        }
开发者ID:petekcchen,项目名称:blog,代码行数:25,代码来源:AccountTests.cs

示例11: RlfpAutomation_When_RegisterAndAddIncome_Then_WeHaveAChartWithIncomeOnIt

        public void RlfpAutomation_When_RegisterAndAddIncome_Then_WeHaveAChartWithIncomeOnIt()
        {
            var name = "WebDriverTester";
            var emailAddress = string.Format("WebDriverTester+{0}@nickmeldrum.com", Guid.NewGuid());

            using (var browser = new ChromeDriver()) {

                // arrange
                var loginPage = RlfpPageFactory.Get<RlfpLoginPage>(browser);
                loginPage.Browse();

                // act
                loginPage.BuildPlanPanelForm.Name = name;
                loginPage.BuildPlanPanelForm.Gender = Gender.Male;
                loginPage.BuildPlanPanelForm.MonthOfBirth = Month.January;
                loginPage.BuildPlanPanelForm.YearOfBirth = 1980;

                var registerPage = loginPage.BuildPlanPanelForm.Submit();

                registerPage.EmailAddress = emailAddress;
                registerPage.ConfirmEmailAddress = emailAddress;
                registerPage.Password = "password";
                registerPage.TermsAndConditionsAccepted = true;

                var financialFuturePage = registerPage.Submit();

                // assert
                Assert.That(financialFuturePage.WelcomeMessage.ToLower(CultureInfo.InvariantCulture),
                    Is.EqualTo(string.Format("Welcome {0}", name).ToLower(CultureInfo.InvariantCulture)));

                browser.Quit();
            }
        }
开发者ID:nickmeldrum,项目名称:selenium-ide-scripts,代码行数:33,代码来源:RLFPWebDriverAutomationFixture.cs

示例12: GetDriver

 public static IWebDriver GetDriver(string driver, Devices device)
 {
     DeviceModel model = Device.Get(device);
     IWebDriver webDriver;
     switch (driver.ToLower())
     {
         case "safari":
             webDriver = new SafariDriver();
             break;
         case "chrome":
             webDriver = new ChromeDriver();
             break;
         case "ie":
             webDriver = new InternetExplorerDriver();
             break;
         //case "firefox":
         default:
             var profile = new FirefoxProfile();
             profile.SetPreference("general.useragent.override", model.UserAgent);
             webDriver = new FirefoxDriver(profile);
             webDriver.Manage().Window.Size = model.ScreenSize;
             break;
     }
     return webDriver;
 }
开发者ID:maartenkuijpers,项目名称:SeleniumTemplate,代码行数:25,代码来源:SeleniumDriverHelper.cs

示例13: ChromeTest

        public virtual void ChromeTest()
        {
            if (!NareshScalerSettings.Default.ChromeEnabled)
                return;

            var driverDir = GetDriverDirectory();

            try
            {
                ChromeDriver = new ChromeDriver(driverDir);
            }
            catch (Exception)
            {
                // Only for master build
                var masterLibDir = LocateDir(Directory.GetCurrentDirectory(), "lib");
                ChromeDriver = new ChromeDriver(masterLibDir);
            }

            ChromeDriver.Manage().Timeouts().ImplicitlyWait(DefaultTimeOutValue);

            try
            {
                RunSeleniumTests(ChromeDriver);
            }
            catch (Exception e)
            {

                RecordError(ChromeDriver, CurrentlyRunningTest, e);
                throw;
            }
        }
开发者ID:hunt3ri,项目名称:NareshScaler,代码行数:31,代码来源:NareshScalerTest.cs

示例14: Index

        public ActionResult Index()
        {
            var driver = new ChromeDriver();

            //driver.Navigate().GoToUrl("http://diesel.elcat.kg");
            driver.Navigate().GoToUrl("http://diesel.elcat.kg/index.php?act=Login");
            // Get the page elements
            var userNameField = driver.FindElementByName("UserName");
            var userPasswordField = driver.FindElementByName("PassWord");
            var loginButton = driver.FindElementByXPath("//input[@name='submit']");

            // Type user name and password
            userNameField.SendKeys("bishkek312");
            userPasswordField.SendKeys("8061");

            // and click the login button
            loginButton.Click();
            driver.Navigate().GoToUrl("http://diesel.elcat.kg/index.php?showtopic=43884872");

            DeleteLastUp(driver);

            var messageField = driver.FindElementById("fast-reply_textarea");
            messageField.SendKeys(upMessageValue);
            var sendButton = driver.FindElementByXPath("//input[@value='Отправить']");

            return new EmptyResult();
            //return View();
        }
开发者ID:web4social,项目名称:dieselUp,代码行数:28,代码来源:HomeController.cs

示例15: Should_page_through_items_in_chrome

        public void Should_page_through_items_in_chrome()
        {
            IWebDriver driver = new ChromeDriver();
            driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(10));
            driver.Navigate().GoToUrl("http://localhost:1392/");

            driver.FindElement(By.Id("login_UserName")).Clear();
            driver.FindElement(By.Id("login_UserName")).SendKeys("Admin");
            driver.FindElement(By.Id("login_Password")).Clear();
            driver.FindElement(By.Id("login_Password")).SendKeys("testing");
            driver.FindElement(By.Id("login_LoginButton")).Click();

            driver.FindElement(By.LinkText("Orders")).Click();

            for (int i = 0; i < 82; i++)
            {
                IWebElement nextButton = driver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_ImageButtonNext"));

                nextButton.Click();

                IWebElement pageCount = driver.FindElement(By.Id("ContentPlaceHolder1_GridView1_ctl00_TextBoxPage"));

                int pageNumber = int.Parse(pageCount.GetAttribute("value"));

                Assert.AreEqual(i +2 , pageNumber);
            }

            driver.FindElement(By.Id("LoginStatus1")).Click(); ;
            driver.Quit();
        }
开发者ID:NathanGloyn,项目名称:Selenium-UI-Testing,代码行数:30,代码来源:When_viewing_orders.cs


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