AddArgument() public method

Adds a single argument to the list of arguments to be appended to the Chrome.exe command line.
public AddArgument ( string argument ) : void
argument string The argument to add.
return void
コード例 #1
23
 public void TestHappyPathChrome()
 {
     ChromeOptions co = new ChromeOptions();
     co.AddArgument("--test-type");
     ChromeDriver cd = new ChromeDriver("C:\\Users\\ehelin\\Downloads\\chromedriver_win32", co);
     TestHappyPath(cd);
 }
コード例 #2
1
 private static ChromeOptions GetChromeOptions()
 {
     var option = new ChromeOptions();
     option.AddArgument("start-maximized");
     option.AddExtension(@"C:\downloads\GoogleAnalytics.crx");
     option.Proxy = null;
     return option;
 }
コード例 #3
1
ファイル: GrindaModel.cs プロジェクト: XelGar256/Scrap
        public GrindaModel(string username, string password, BackgroundWorker bw, bool openGrinda)
        {
            string numbers = "";

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

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

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

            try
            {
                driver.FindElement(By.Id("login_username")).SendKeys(username);
                driver.FindElement(By.Id("pwd")).SendKeys(password);

                driver.FindElement(By.ClassName("btn-lg")).Click();
            }
            catch { }

            IList<IWebElement> smalls = driver.FindElements(By.TagName("small"));
            foreach (IWebElement small in smalls)
            {
                if (small.Text.Contains("Last Checkin"))
                {
                    numbers = small.Text;
                    break;
                }
            }

            if (DateTime.Parse(numbers.Split(' ')[2]).DayOfYear != DateTime.Now.DayOfYear)
            {
                checkIn(driver);
            }
        }
コード例 #4
1
        /// <summary>
        /// Creates the web driver.
        /// </summary>
        /// <param name="browserType">Type of the browser.</param>
        /// <param name="browserFactoryConfiguration">The browser factory configuration.</param>
        /// <returns>The created web driver.</returns>
        /// <exception cref="System.InvalidOperationException">Thrown if the browser is not supported.</exception>
        internal static IWebDriver CreateWebDriver(BrowserType browserType, BrowserFactoryConfigurationElement browserFactoryConfiguration)
        {
            IWebDriver driver;
            if (!RemoteDriverExists(browserFactoryConfiguration.Settings, browserType, out driver))
            {
                switch (browserType)
                {
                    case BrowserType.IE:
                        var explorerOptions = new InternetExplorerOptions { EnsureCleanSession = browserFactoryConfiguration.EnsureCleanSession };
                        driver = new InternetExplorerDriver(explorerOptions);
                        break;
                    case BrowserType.FireFox:
                        driver = GetFireFoxDriver(browserFactoryConfiguration);
                        break;
                    case BrowserType.Chrome:
                        var chromeOptions = new ChromeOptions { LeaveBrowserRunning = false };
                        if (browserFactoryConfiguration.EnsureCleanSession)
                        {
                            chromeOptions.AddArgument("--incognito");
                        }

                        driver = new ChromeDriver();
                        break;
                    case BrowserType.PhantomJS:
                        driver = new PhantomJSDriver();
                        break;
                    case BrowserType.Safari:
                        driver = new SafariDriver();
                        break;
                    default:
                        throw new InvalidOperationException(string.Format("Browser type '{0}' is not supported in Selenium local mode. Did you mean to configure a remote driver?", browserType));
                }
            }

            // Set Driver Settings
            var managementSettings = driver.Manage();
           
            // Set timeouts
            managementSettings.Timeouts()
                .ImplicitlyWait(browserFactoryConfiguration.ElementLocateTimeout)
                .SetPageLoadTimeout(browserFactoryConfiguration.PageLoadTimeout);

            // Maximize window
            managementSettings.Window.Maximize();

            return driver;
        }
コード例 #5
0
        internal void Launch(bool mobile, string url = "https://www.bing.com/") {
            Quit();
            _viewModel.ResetProfileCommand.RaiseCanExecuteChanged();

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

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

            if (mobile)
                options.EnableMobileEmulation("Google Nexus 5");

            try {
                _driver = new ChromeDriver(service, options);
                _driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(3));

                _builder = new Actions(_driver);

                LogUpdate("Launching Chrome " + (mobile ? "Mobile" : "Desktop"), Colors.CadetBlue);

                if (url != null)
                    _driver.Navigate().GoToUrl(url);
            }
            catch (Exception ex) {
                LogUpdate("Error Launching Chrome " + (mobile ? "Mobile" : "Desktop") + "\r\n" + ex.Message, Colors.Red);
                service.Dispose();
            }
        }
コード例 #6
0
ファイル: InboxModel.cs プロジェクト: XelGar256/Scrap
        public InboxModel(string username, string password, BackgroundWorker bw, bool tv)
        {
            ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
            service.HideCommandPromptWindow = true;

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

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

            try
            {
                driver.FindElement(By.Id("loginname")).Clear();
                driver.FindElement(By.Id("pwd")).Clear();
                driver.FindElement(By.Id("loginname")).SendKeys(username);
                driver.FindElement(By.Id("pwd")).SendKeys(password);
                Helpers.wait(1000);
                driver.FindElement(By.ClassName("submit2")).Click();
            }
            catch { }

            try
            {
                if (driver.FindElement(By.Id("emailsBlock")).FindElement(By.ClassName("textBox")).Text != "0")
                {
                    driver.FindElement(By.Id("emailsBlock")).FindElement(By.ClassName("textBox")).Click();
                }
            }
            catch { }

            if (!tv)
            {
                try
                {
                    driver.FindElement(By.ClassName("videos")).Click();
                    videos(driver);
                }
                catch { }
            }
            else if (tv)
            {
                try
                {
                    driver.FindElement(By.ClassName("tv")).Click();
                    Helpers.wait(2000);
                    Helpers.ByClass(driver, "jw-icon");
                    while (true)
                    {
                        try
                        {
                            driver.FindElement(By.Id("tvStillTherePopupContinue")).Click();
                        }
                        catch { }
                    }
                }
                catch { }
            }
        }
コード例 #7
0
        private ChromeDriver LaunchChrome()
        {
            // Disable the remember password popups, and make sure it's full screen so that Bootstrap elements aren't hidden
            ChromeOptions options = new ChromeOptions();
            options.AddArgument("--incognito");
            options.AddArgument("--start-maximized");
            ChromeDriver chromeDriver = new ChromeDriver(options);
            chromeDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(2));

            return chromeDriver;
        }
コード例 #8
0
        private void Init()
        {
            StopAllDrivers();

            var options = new ChromeOptions();
            var profilePath = ConfigurationManager.AppSettings["ProfilePath"];
            options.AddArgument("--start-maximized");
            options.AddArgument("--user-data-dir=" + profilePath);
            Driver = new ChromeDriver(options);
            Driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(Timeout));
        }
コード例 #9
0
        public IWebDriver CreateNewInstance()
        {
            var options = new ChromeOptions();
            options.AddArgument("test-type");
            if (SeleniumTestsConfiguration.ChromeDriverIncognito)
            {
                options.AddArgument("--disable-extensions");
            }

            var driver = new ChromeDriverWrapper(options);
            driver.SetDefaultTimeouts();
            return driver;
        }
コード例 #10
0
 public void TestThatGoogleFindsJavaNotCsharp()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--no-sandbox");
     options.AddArgument("--disable-extensions");
     options.AddArgument("--start-maximized");
     IWebDriver driver = new ChromeDriver(options);
     driver.Navigate().GoToUrl("http://google.com");
     driver.FindElement(By.Id("lst-ib")).SendKeys("Java");
     driver.FindElement(By.Name("btnK")).Submit();
     Thread.Sleep(1000);
     Assert.IsTrue(driver.FindElement(By.CssSelector("#rso > div > div:nth-child(1) > div > h3 > a")).Text.Contains("Java"));
     Assert.IsFalse(driver.FindElement(By.CssSelector("#rso > div > div:nth-child(1) > div > h3 > a")).Text.Contains("C#"));
     driver.Close();
 }
コード例 #11
0
 public void Login()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--no-sandbox");
     options.AddArgument("--disable-extensions");
     options.AddArgument("--start-maximized");
     driver = new ChromeDriver(options);
     driver.Navigate().GoToUrl("http://www.qa.way2automation.com");
     driver.FindElement(By.CssSelector("#load_form > h3"));
     driver.FindElement(By.CssSelector("#load_form > div > div.span_3_of_4 > p > a[href='#login']")).Click();
     driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(5) > input[name='username']")).SendKeys("j2bwebdriver");
     driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(6) > input[name='password']")).SendKeys("j2bwebdriver");
     driver.FindElements(By.CssSelector("#load_form > div > div.span_1_of_4 > input"))[1].Submit();
     Thread.Sleep(1000);
 }
コード例 #12
0
ファイル: TestBase.cs プロジェクト: rrsc/Dnn.Platform
		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;
		}
コード例 #13
0
ファイル: Browser.cs プロジェクト: agross/mspec-samples
        public void Start()
        {
            var options = new ChromeOptions();
              options.AddArgument("--test-type");

              Instance = new RemoteWebDriver(ChromeDriver.BaseUrl, options.ToCapabilities());
        }
コード例 #14
0
ファイル: Tools.cs プロジェクト: FaisalZ/FiVES
 public static IWebDriver CreateDriver()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--disable-cache");
     var driver = new ChromeDriver(options);
     return driver;
 }
コード例 #15
0
 private static ChromeOptions GetChromeOptions()
 {
     ChromeOptions option = new ChromeOptions();
     option.AddArgument("start-maximized");
     option.Proxy = null;
     return option;
 }
コード例 #16
0
        private IWebDriver get_local_chrome_driver()
        {
            var options = new OpenQA.Selenium.Chrome.ChromeOptions();

            //options.BinaryLocation = "/usr/share/iron/chrome-wrapper";
            options.BinaryLocation = "/usr/share/iron/chrome";
            options.AddArgument("--disable-extensions");
            // options.BinaryLocation = "/wd/hub";
            options.DebuggerAddress = Debugger_Host_And_Port;
            //new ChromeDriver(chrome_driver_binary, chrome_options=options);

            return(new ChromeDriver(BinaryLocation, options));
            //return new ChromeDriver("/media/jhaines/tera27/file-set/workspace/CoffeeBreak/src/test/bin/Debug/netcoreapp2.1/");

            /*
             * System.setProperty("webdriver.chrome.driver","");
             *
             *
             *          using (var driver = new ChromeDriver("/media/jhaines/tera27/file-set/workspace/coffeebreak-test/bin/Debug/netcoreapp2.1/", options))
             *
             */

            // Initialize the Chrome Driver
            //using (var driver = new ChromeDriver("/media/jhaines/tera27/file-set/workspace/coffeebreak-test/bin/Debug/netcoreapp2.1/", options))
        }
コード例 #17
0
 /// <summary>
 /// Returns an initialised Chrome Web Driver.
 /// </summary>
 /// <remarks>You need to have chromedriver.exe embedded into your assembly and have Chrome installed on the machine running the test</remarks>
 /// <returns>Initialised Chrome driver</returns>
 public static ChromeDriver Chrome()
 {
     var options = new ChromeOptions();
     // addresses issue: https://code.google.com/p/chromedriver/issues/detail?id=799
     options.AddArgument("test-type");
     return new WebDriverBuilder<ChromeDriver>(() => new ChromeDriver(options))
         .WithFileName("chromedriver.exe");
 }
コード例 #18
0
ファイル: BaseClass.cs プロジェクト: Saltorel/BDD-CSharp
        private static ChromeOptions GetChromeOptions()
        {
            ChromeOptions option = new ChromeOptions();
            option.AddArgument("start-maximized");

            // option.AddExtension(@"C:\Users\rahul.rathore\Desktop\Cucumber\extension_3_0_12.crx");
            return option;
        }
コード例 #19
0
 public static void CreateWebDriver()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--start-maximized");
     driver = new ChromeDriver("../../Drivers", options, TimeSpan.FromSeconds(Timeout));
     driver.Manage().Timeouts().SetScriptTimeout(TimeSpan.FromSeconds(Timeout));
     driver.Manage().Cookies.DeleteAllCookies();
     driver.Url = URL;
 }
コード例 #20
0
        public void GetChromeBrowserWithOptions()
        {
            var options = new ChromeOptions();
            options.AddArgument("-incognito");

            Assume.That(_driver.GetNuGetChromeDriver());
            _driver = WebDriverFactory.GetBrowser<ChromeDriver, ChromeOptions>(options, "http://rickcasady.blogspot.com/");
           
        }
コード例 #21
0
 public void FailedLogin()
 {
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--no-sandbox");
     options.AddArgument("--disable-extensions");
     options.AddArgument("--start-maximized");
     IWebDriver driver = new ChromeDriver(options);
     driver.Navigate().GoToUrl("http://www.qa.way2automation.com/");
     driver.FindElement(By.CssSelector("#load_form > h3"));
     driver.FindElement(By.CssSelector("#load_form > div > div.span_3_of_4 > p > a[href='#login']")).Click();
     driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(5) > input[name='username']")).SendKeys("j2bwebdriver");
     driver.FindElement(By.CssSelector("#load_form > fieldset:nth-child(6) > input[name='password']")).SendKeys("incorrectpassword");
     driver.FindElements(By.CssSelector("#load_form > div > div.span_1_of_4 > input"))[1].Submit();
     Thread.Sleep(3000); 
     Assert.IsTrue(driver.FindElement(By.CssSelector("#alert1")).Text.Contains("Invalid username password."));
     Assert.IsTrue(driver.FindElement(By.CssSelector("body")).Text.Contains("Username"));
     Assert.IsTrue(driver.FindElement(By.CssSelector("body")).Text.Contains("Password")); 
     driver.Close();
 }
コード例 #22
0
        private static IWebDriver CreateChromeDriver(string driversDirectory)
        {
            var chromeService = Chrome.ChromeDriverService.CreateDefaultService(driversDirectory);

            chromeService.HideCommandPromptWindow = true;
            var chromeOptions = new Chrome.ChromeOptions
            {
                PageLoadStrategy = PageLoadStrategy.None
            };

            chromeOptions.AddArgument("disable-infobars");
            chromeOptions.AddArgument("--disable-bundled-ppapi-flash");
            chromeOptions.AddArgument("--log-level=3");
            chromeOptions.AddArgument("--silent");
            chromeOptions.AddUserProfilePreference("credentials_enable_service", false);
            chromeOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
            chromeOptions.AddUserProfilePreference("auto-open-devtools-for-tabs", false);
            return(new Chrome.ChromeDriver(chromeService, chromeOptions));
        }
コード例 #23
0
        protected IWebDriver InitChromeDriver() {
            const string cacheDir = @"C:\SeleniumTestFolder";

            var crOptions = new ChromeOptions();
            crOptions.AddArgument(@"--user-data-dir=" + cacheDir);
            var cd = new ChromeDriver(crOptions);

            // test workaround for chromedriver problem https://groups.google.com/forum/#!topic/selenium-users/nJ0NF1UJ3WU
            Thread.Sleep(5000);
            return cd;
        }
コード例 #24
0
        /// <summary>
        /// setup webdriver. chromedriver is a default value
        /// </summary>
        /// <returns>driver</returns>
        public static IWebDriver SetupBrowser()
        {
            String browserName = Configuration.GetBrowser();

            if (browserName == "chrome")
            {
                ChromeOptions options = new ChromeOptions();
                options.AddArgument("--start-maximized");
                return new ChromeDriver(Path.GetFullPath(DriverPath), options);
            }
            return new ChromeDriver(Path.GetFullPath(DriverPath));
        }
コード例 #25
0
        private static DriverOptions getBrowserOptions(DriverConfig config)
        {
            DriverOptions opts;

            switch (config.Browser)
            {
            case "firefox":
                var ffOpts = new OpenQA.Selenium.Firefox.FirefoxOptions();

                if (config.Headless)
                {
                    ffOpts.AddArgument("--headless");
                }
                ffOpts.LogLevel = FirefoxDriverLogLevel.Fatal;

                opts = ffOpts;
                break;

            case "chrome":
                var chromeOpts = new OpenQA.Selenium.Chrome.ChromeOptions();
                if (config.Headless)
                {
                    chromeOpts.AddArgument("--headless");
                }
                chromeOpts.AddArgument("--log-level=3");
                chromeOpts.AddArgument("--silent");

                opts = chromeOpts;
                break;

            default:
                throw new NotImplementedException("Not implemented for browser: " + config.Browser);
            }
            opts.SetLoggingPreference(LogType.Browser, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Driver, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Client, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Profiler, LogLevel.Off);
            opts.SetLoggingPreference(LogType.Server, LogLevel.Off);
            return(opts);
        }
コード例 #26
0
 public void TestThatGoogleFindsCheeseNotBacon()
 {
     // Setup ChromeDriver configuration
     ChromeOptions options = new ChromeOptions();
     options.AddArgument("--no-sandbox");
     options.AddArgument("--disable-extensions");
     options.AddArgument("--start-maximized");
     IWebDriver driver = new ChromeDriver(options);
     // Choose page link
     driver.Navigate().GoToUrl("http://google.com");
     // Setup ChromeDriver configuration
     driver.FindElement(By.Id("lst-ib")).SendKeys("Cheese");
     driver.FindElement(By.Name("btnK")).Submit();
     // Wait for webelements to load
     Thread.Sleep(1000);
     // Assertion on first search result position		
     Assert.IsTrue(driver.FindElement(By.CssSelector("#rso > div > div:nth-child(1) > div > h3 > a")).Text.Contains("Cheese"));
     Assert.IsTrue(driver.FindElement(By.CssSelector("#rso > div > div:nth-child(1) > div > h3 > a")).Text.Contains("Wikipedia"));
     Assert.IsFalse(driver.FindElement(By.CssSelector("#rso > div > div:nth-child(1) > div > h3 > a")).Text.Contains("Bacon"));
     // Closing browser window
     driver.Close();
 }
コード例 #27
0
 private Dictionary<string, string> pageParentURLMapping;  //Key is current Page, Content is parent Page
 public Crawler(CrawlerOptions options)
 {
     _options = options;
     pagesVisited = new HashSet<Uri>();
     pagesNotFound = new HashSet<Uri>();
     pagesToVisit = new List<Uri>();
     _watch = new Stopwatch();
     pagesErrorList = new DataTable();
     pagesErrorList = ExcelHandler.InitTable(pagesErrorList);
     logger = LogManager.GetCurrentClassLogger();
     pageParentURLMapping = new Dictionary<string, string>();
     var chromeOptions = new ChromeOptions();
     chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
     _driver = new ChromeDriver(chromeOptions);
 }
コード例 #28
0
        public IWebDriver Current()
        {
            //DesiredCapabilities chromeCapabilities = new DesiredCapabilities();
            Browser = ConfigurationManager.AppSettings["browser"];
            Testenvironment = ConfigurationManager.AppSettings["Environment"];
            Environment.SetEnvironmentVariable("Testenvironment", Testenvironment);

            EnvironmentConfiguration.CreateInstance(@"Framework\Environment.xml", Testenvironment);
            Url = EnvironmentConfiguration.Instance.GetEnvironmentVariable("URL");
            //Url1 = EnvironmentConfiguration.Instance.GetEnvironmentVariable("URL1");

            if (!FeatureContext.Current.ContainsKey("browser"))
            {
                switch (Browser)
                {
                    case "IE":
                        break;

                    case "FIREFOX":
                        var profileManager = new FirefoxProfileManager();
                        FirefoxProfile profile = profileManager.GetProfile("SeleniumProfile");
                        FeatureContext.Current["browser"] = new FirefoxDriver(profile);
                        ScenarioContext.Current["browser"] = FeatureContext.Current["browser"];
                        driver = (IWebDriver) ScenarioContext.Current["browser"];
                        driver.Manage().Window.Maximize();
                        driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 30));
                        break;

                    case "CHROME":
                        var options = new ChromeOptions();
                        options.AddArgument("--start-maximized");
                        driver = new ChromeDriver(options);
                        //FeatureContext.Current["browser"] = new ChromeDriver(options);
                        //ScenarioContext.Current["browser"] = FeatureContext.Current["browser"];
                        //driver = (IWebDriver)ScenarioContext.Current["browser"];
                        break;
                }
            }
            else
            {
                ScenarioContext.Current["browser"] = FeatureContext.Current["browser"];
                driver = (IWebDriver) ScenarioContext.Current["browser"];
            }
            return driver;
        }
コード例 #29
0
        public void SetUpSelenium()
        {
            _driver = new FirefoxDriver();

            if (_driver.GetType() == typeof (FirefoxDriver))
            {
                _driver.Manage().Window.Maximize();
            }
            if (_driver.GetType() == typeof (ChromeDriver))
            {
                var options = new ChromeOptions();
                options.AddArgument("--start-maximized");
                _driver = new ChromeDriver(options);
            }

            _driver.Manage().Timeouts().ImplicitlyWait(new TimeSpan(0, 0, 0, 5));
            _actions = new Actions(_driver);
        }
コード例 #30
0
ファイル: Guard.aspx.cs プロジェクト: ripanpaul1/GeneralAgent
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string strUserCode = txtUserCode.Text;
        string strPassword = txtPassword.Text;

        var options = new OpenQA.Selenium.Chrome.ChromeOptions();

        options.AddArgument("headless");
        var driver = new ChromeDriver(@"E:/Work/Demo/Driver/Chrome", options);

        //var driver = new OpenQA.Selenium.IE.InternetExplorerDriver(@"E:\Work\Demo\IEDriverServer_x64_2.39.0");
        //driver.Navigate().GoToUrl("http://home.centurysurety.com/");
        driver.Navigate().GoToUrl("https://gigezrate.guard.com/comm/asclogin/agents.htm");
        //String ste = driver.PageSource;

        IWebElement eUserCode = driver.FindElement(By.Name("USER_CODE"));

        eUserCode.SendKeys(strUserCode);
        //eUserCode.SendKeys("jcorallo");


        IWebElement ePassword = driver.FindElement(By.Name("PASSWORD"));

        ePassword.SendKeys(strPassword);
        //ePassword.SendKeys("Sasha5128");


        driver.FindElement(By.XPath("//input[@value='Log in']")).Click();
        driver.Navigate().GoToUrl("https://gigezrate.guard.com/dotnet/mvc/asc/ascheader/homepage/index");
        //String ste1 = driver.PageSource;
        //string[] arr = Regex.Split(ste1, "</div>");
        string strConect = "";
        var    doc       = new HtmlAgilityPack.HtmlDocument();

        doc.LoadHtml(driver.PageSource);
        strConect = "<table>" + doc.GetElementbyId("TabContents").InnerHtml + "</table>";
        string correctString = strConect.Replace("/dotnet/mvc/uw/ezrate/asc_prerate/home/Index?", "CreateQuoteGuard.aspx");

        dvContent.InnerHtml     = correctString;
        mvGuard.ActiveViewIndex = 1;

        //upnlContent.Update();
    }
コード例 #31
0
        void OpenBrows()
        {
            ticktak.Start();
            var driverService = ChromeDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = !consoleVisib.Checked;
            if (VisBrows == 0)
            {
                ChromeOptions SettingBr = new OpenQA.Selenium.Chrome.ChromeOptions();
                SettingBr.AddArgument("headless");
                Browser = new ChromeDriver(driverService, SettingBr);
            }
            else
            {
                Browser = new OpenQA.Selenium.Chrome.ChromeDriver(driverService);
            }
            Browser.Navigate().GoToUrl("http://moodle.dgma.donetsk.ua/login/index.php");
            CheckBrows = 1;
        }
コード例 #32
0
 private static void CrawlFirstPage(Uri startUrl)
 {
     ChromeOptions chromeOptions = new ChromeOptions();
     chromeOptions.AddArgument("--user-agent=" + _options.UserAgent);
     
     var _driver = new RemoteWebDriver(_options.RemoteHubUrl, chromeOptions.ToCapabilities());
     try
     {
         _driver.Navigate().GoToUrl(startUrl);
         SaveHtmlAndScreenShot(startUrl, _driver);
         pageVisitedURLMapping.TryAdd(startUrl, startUrl);
         _driver.Close();
         _driver.Quit();
     }
     catch (Exception ex)
     {
         logger.Info(" Thread : " + startUrl.PathAndQuery + " Error at " + ex.StackTrace);
         _driver.Close();
         _driver.Quit();
     }
 }
コード例 #33
0
ファイル: TestBase.cs プロジェクト: kp-xcess/Dnn.Platform
		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;
						//firefoxProfile.SetPreference("browser.cache.disk.enable", false);
						//firefoxProfile.SetPreference("browser.cache.memory.enable", false);
						//firefoxProfile.SetPreference("browser.cache.offline.enable", false);
						//firefoxProfile.SetPreference("network.http.use-cache", false);

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

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

			driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromMilliseconds(500));
			driver.Manage().Window.Maximize();
			return driver;
		}
コード例 #34
0
        private QA.IWebDriver InitWebDriver(string cache_dir, bool loadImage = true, string useragent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36")
        {
            if (!Directory.Exists(cache_dir))
            {
                Directory.CreateDirectory(cache_dir);
            }
            QA.IWebDriver theDriver = null;
            switch (this.browser)
            {
            case Browsers.IE:
            {
                InternetExplorerDriverService driverService = InternetExplorerDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver  = new QA.IE.InternetExplorerDriver(driverService, _ieOptions);
                _ProcessID = driverService.ProcessId;
            }; break;

            case Browsers.Chrome:
            {
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.Port = new Random().Next(1000, 2000);
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                ChromeOptions options = new QA.Chrome.ChromeOptions();
                options.AddArgument("--window-size=" + Screen.PrimaryScreen.WorkingArea.Width + "x" + Screen.PrimaryScreen.WorkingArea.Height);
                options.AddArgument("--disable-gpu");
                options.AddArgument("--disable-extensions");
                options.AddArgument("--no-sandbox");
                options.AddArgument("--disable-dev-shm-usage");
                options.AddArgument("--disable-java");
                options.AddArgument("--user-agent=" + useragent);
                options.AddArgument(@"--user-data-dir=" + cache_dir);
                if (loadImage == false)
                {
                    options.AddUserProfilePreference("profile.managed_default_content_settings.images", 2);        //不加载图片
                }
                theDriver  = new QA.Chrome.ChromeDriver(driverService, options, TimeSpan.FromSeconds(240));
                _ProcessID = driverService.ProcessId;
            };
                break;

            case Browsers.Firefox:
            {
                var driverService = FirefoxDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds = driverService;
                FirefoxProfile profile = new FirefoxProfile();
                if (loadImage == false)
                {
                    profile.SetPreference("permissions.default.image", 2);
                    // 关掉flash
                    profile.SetPreference("dom.ipc.plugins.enabled.libflashplayer.so", false);
                }
                FirefoxOptions options = new FirefoxOptions();
                options.Profile = profile;
                theDriver       = new QA.Firefox.FirefoxDriver(driverService, options, TimeSpan.FromMinutes(240));
                _ProcessID      = driverService.ProcessId;
            };
                break;

            case Browsers.Safari:
            {
                SafariDriverService driverService = SafariDriverService.CreateDefaultService(Application.StartupPath + "\\Drivers\\");
                driverService.HideCommandPromptWindow = true;
                driverService.SuppressInitialDiagnosticInformation = true;
                ds         = driverService;
                theDriver  = new QA.Safari.SafariDriver(driverService);
                _ProcessID = driverService.ProcessId;
            };
                break;

            default:
            {
                QA.IE.InternetExplorerOptions _ieOptions = new QA.IE.InternetExplorerOptions();
                _ieOptions.IntroduceInstabilityByIgnoringProtectedModeSettings = true;
                theDriver = new QA.IE.InternetExplorerDriver(_ieOptions);
            };
                break;
            }
            //theDriver.Manage().Window.Maximize();
            return(theDriver);
        }
コード例 #35
0
    protected void btnLoadContent_Click(object sender, EventArgs e)
    {
        //lblMsg.Text = "Please wait.";
        //mpShow.Show();
        var options = new OpenQA.Selenium.Chrome.ChromeOptions();

        options.AddArgument("headless");
        var driver = new ChromeDriver(@"E:/Work/Demo/Driver/Chrome", options);

        //var driver = new OpenQA.Selenium.IE.InternetExplorerDriver(@"E:\Work\Demo\IEDriverServer_x64_2.39.0");
        //driver.Navigate().GoToUrl("http://home.centurysurety.com/");
        driver.Navigate().GoToUrl("https://gigezrate.guard.com/comm/asclogin/agents.htm");
        //String ste = driver.PageSource;

        IWebElement eUserCode = driver.FindElement(By.Name("USER_CODE"));

        eUserCode.SendKeys("jcorallo");


        IWebElement ePassword = driver.FindElement(By.Name("PASSWORD"));

        ePassword.SendKeys("Sasha5128");


        driver.FindElement(By.XPath("//input[@value='Log in']")).Click();
        //driver.Navigate().GoToUrl("https://gigezrate.guard.com/dotnet/mvc/asc/ascheader/homepage/index");
        driver.Navigate().GoToUrl("https://gigezrate.guard.com/dotnet/mvc/uw/ezrate/asc_prerate/home/Index?");
        String strPageSource = driver.PageSource;
        //if (ste1.StartsWith("gtmvcform_"))
        //{
        //    // Will match second possibility.
        //    Console.WriteLine(s);
        //    return;
        //}
        //string test = ste1;
        //int index1 = test.IndexOf("gtmvcform_");
        //if (index1 != -1)
        //{
        //    string result2 = test.Remove(index1);
        //}


        //string s = driver.PageSource;
        string strFormID = string.Empty;

        if (strPageSource.Contains("gtmvcform_"))
        {
            int x = strPageSource.IndexOf("gtmvcform_");
            int t = strPageSource.Substring(x).IndexOf(" ");
            strFormID = strPageSource.Substring(x, t);
        }
        strFormID = strFormID.Replace("\"", "");
        //New Code

        HtmlDocument doc1 = new HtmlDocument();

        doc1.LoadHtml(driver.PageSource);


        // HtmlNode secondForm = doc1.GetElementbyId(strFormID);
        string strPagecontent = string.Empty;

        doc1.DocumentNode.Descendants()
        .Where(n => n.Id == "presubmissionlist_lnk_div")
        .ToList()
        .ForEach(n => n.Remove());
        string classToFind          = "GTtabBox";
        var    allElementsWithClass =
            doc1.DocumentNode.SelectNodes(string.Format("//*[contains(@class,'{0}')]", classToFind));

        foreach (var item in allElementsWithClass)
        {
            strPagecontent += item.InnerHtml;
        }
        string strPagecontent1 = allElementsWithClass[0].InnerHtml;
        string strPagecontent3 = allElementsWithClass[3].InnerHtml;


        HtmlAgilityPack.HtmlNodeCollection ScriptNodes = doc1.DocumentNode.SelectNodes("//script");
        HtmlAgilityPack.HtmlNodeCollection StyleNodes  = doc1.DocumentNode.SelectNodes("//link");

        string correctString = string.Empty;

        foreach (HtmlNode node in ScriptNodes)
        {
            correctString += node.OuterHtml;
        }
        foreach (HtmlNode node in StyleNodes)
        {
            correctString += node.OuterHtml;
        }
        string correctString1 = correctString.Replace("/dotnet/mvc/", "https://gigezrate.guard.com/dotnet/mvc/");

        //New code


        //var doc = new HtmlAgilityPack.HtmlDocument();
        //doc.LoadHtml(driver.PageSource);
        //string strConect = doc.GetElementbyId(strFormID).InnerHtml;
        //string correctString = strConect.Replace("/dotnet/mvc/uw/ezrate/asc_prerate/home/Index?", "CreateQuoteGuard.aspx");
        strPagecontent3 = strPagecontent3 + correctString1;

        //HtmlDocument doc = new HtmlDocument();

        //doc.LoadHtml(strPagecontent3);

        //HtmlAgilityPack.HtmlNodeCollection divNodes = doc1.DocumentNode.SelectNodes("//div");
        //foreach (HtmlNode node in divNodes)
        //{
        //    if()
        //}
        //doc1.DocumentNode.Descendants()
        //        .Where(n => n.Id == "presubmissionlist_lnk_div")
        //        .ToList()
        //        .ForEach(n => n.Remove());
        dvContent.InnerHtml = strPagecontent3;
    }
コード例 #36
0
ファイル: PedModel.cs プロジェクト: XelGar256/Scrap
        public PedModel(string username, string password, BackgroundWorker bw, bool openPed)
        {
            ChromeDriverService service = ChromeDriverService.CreateDefaultService(App.Folder);
            service.HideCommandPromptWindow = true;

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

            IWebDriver driver = new ChromeDriver(service, options);
            driver.Navigate().GoToUrl("http://www.pedtoclick.com/index.php?view=login");

            try
            {
                driver.FindElement(By.Name("username")).SendKeys(username);
                driver.FindElement(By.Name("password")).SendKeys(password);
                driver.FindElement(By.Name("password")).SendKeys(Keys.Enter);
            }
            catch { }
            finally { }
            Helpers.ByClass(driver, "login");

            Helpers.wait(5000);
            if (!openPed)
            {
                driver.Navigate().GoToUrl("http://www.pedtoclick.com/superRewards.php");

                Helpers.wait(10000);

                IList<IWebElement> iframes = driver.FindElements(By.TagName("iframe"));
                foreach (IWebElement iframe in iframes)
                {
                    Debug.WriteLine(iframe.Text);
                }

                Helpers.switchToBrowserByString(driver, "PEDtoClick");
                Helpers.switchFrameByNumber(driver, 0);
                try
                {
                    IList<IWebElement> lis = driver.FindElements(By.TagName("li"));
                    Debug.WriteLine(lis.Count);
                    IList<IWebElement> navOptions = driver.FindElements(By.ClassName("nav-option"));
                    Debug.WriteLine(navOptions.Count);
                }
                catch { }

                Helpers.switchToBrowserByString(driver, "PEDtoClick");
                Helpers.switchFrameByNumber(driver, 1);
                try
                {
                    IList<IWebElement> lis = driver.FindElements(By.TagName("li"));
                    Debug.WriteLine(lis.Count);
                    IList<IWebElement> navOptions = driver.FindElements(By.ClassName("nav-option"));
                    Debug.WriteLine(navOptions.Count);
                }
                catch { }

                Helpers.switchToBrowserByString(driver, "PEDtoClick");
                Helpers.switchFrameByNumber(driver, 2);
                try
                {
                    IList<IWebElement> lis = driver.FindElements(By.TagName("li"));
                    Debug.WriteLine(lis.Count);
                    IList<IWebElement> navOptions = driver.FindElements(By.ClassName("nav-option"));
                    Debug.WriteLine(navOptions.Count);
                    driver.FindElement(By.LinkText("Video")).Click();

                    Helpers.wait(5000);

                    try
                    {
                        IList<IWebElement> h2s = driver.FindElements(By.TagName("h2"));
                        foreach (IWebElement h2 in h2s)
                        {
                            if (h2.Text.Contains("HyprMX"))
                            {
                                h2.Click();
                                superRewards(driver);
                            }
                        }
                    }
                    catch { }
                }
                catch { }

            }
        }
コード例 #37
0
        private static IWebDriver CreateNewWebDriver(string webBrowserName, BrowserType type, out IntPtr mainWindowHandle, string driversDirectory)
        {
            webBrowserName = webBrowserName.ToLower();
            IWebDriver     iWebDriver            = null;
            List <Process> processesBeforeLaunch = GetProcesses();
            string         newProcessFilter      = string.Empty;

            switch (type)
            {
            case BrowserType.Chrome:
                var chromeService = Chrome.ChromeDriverService.CreateDefaultService(driversDirectory);
                chromeService.HideCommandPromptWindow = true;
                var chromeOptions = new Chrome.ChromeOptions();
                chromeOptions.PageLoadStrategy = PageLoadStrategy.None;
                chromeOptions.AddArgument("disable-infobars");
                chromeOptions.AddArgument("--disable-bundled-ppapi-flash");
                chromeOptions.AddArgument("--log-level=3");
                chromeOptions.AddArgument("--silent");
                chromeOptions.AddUserProfilePreference("credentials_enable_service", false);
                chromeOptions.AddUserProfilePreference("profile.password_manager_enabled", false);
                chromeOptions.AddUserProfilePreference("auto-open-devtools-for-tabs", false);
                //chromeOptions.AddAdditionalCapability("pageLoadStrategy", "none", true);
                iWebDriver       = new Chrome.ChromeDriver(chromeService, chromeOptions);
                newProcessFilter = "chrome";
                break;

            case BrowserType.Firefox:
                var firefoxService = Firefox.FirefoxDriverService.CreateDefaultService(driversDirectory);
                firefoxService.HideCommandPromptWindow = true;
                iWebDriver       = new Firefox.FirefoxDriver(firefoxService);
                newProcessFilter = "firefox";
                break;

            case BrowserType.InternetExplorer:
                IE.InternetExplorerDriverService ieService = IE.InternetExplorerDriverService.CreateDefaultService(driversDirectory);
                ieService.HideCommandPromptWindow = true;
                IE.InternetExplorerOptions options = new IE.InternetExplorerOptions()
                {
                    IgnoreZoomLevel = true
                };
                iWebDriver       = new IE.InternetExplorerDriver(ieService, options);
                newProcessFilter = "iexplore";
                break;

            case BrowserType.Edge:
                var edgeService = Edge.EdgeDriverService.CreateDefaultService(driversDirectory);
                edgeService.HideCommandPromptWindow = true;
                var edgeOptions = new Edge.EdgeOptions();
                edgeOptions.PageLoadStrategy = PageLoadStrategy.Eager;
                iWebDriver       = new Edge.EdgeDriver(edgeService, edgeOptions);
                newProcessFilter = "edge";
                break;

            default:
                throw new ArgumentException($"Could not launch specified browser '{webBrowserName}'");
            }
            var newProcess = GetNewlyCreatedProcesses(newProcessFilter, processesBeforeLaunch);

            mainWindowHandle = (newProcess != null) ? newProcess.MainWindowHandle : IntPtr.Zero;
            return(iWebDriver);
        }
コード例 #38
-1
        private IWebDriver GetDriver(DriverTypes type)
        {
            IWebDriver driver = null;
            switch (type)
            {
                case DriverTypes.IE:
                    driver = new InternetExplorerDriver(
                        new InternetExplorerOptions
                        {
                            UnexpectedAlertBehavior = InternetExplorerUnexpectedAlertBehavior.Default,
                            EnableNativeEvents = true,
                            //ForceCreateProcessApi = true,
                            //BrowserCommandLineArguments = "-private",
                            EnsureCleanSession = true
                        });
                    driver = new NgWebDriver(driver);
                    break;

                case DriverTypes.Chrome:
                    ChromeOptions options = new ChromeOptions();
                    options.AddArgument("--disable-plugins");
                    driver = new ChromeDriver(options);
                    driver = new NgWebDriver(driver);
                    break;
            }
            ((NgWebDriver)driver).IgnoreSynchronization = true;
            return driver;
        }