Exemplo n.º 1
0
        public void TestFixtureSetUp()
        {
            generate.GenerateReports(0, "0", true);
            int i = Convert.ToInt32(ConfigurationManager.AppSettings.Get("Browser"));

            if (i == 1)
            {
                ChromeOptions option = new ChromeOptions();
                option.AddArguments("--ignore-certificate-errors");
                option.AddArguments("--ignore-ssl-errors");
                Browser = new ChromeDriver(iWoekDir, option);
            }
            else
            {
                FirefoxOptions option = new FirefoxOptions();
                option.AddArguments("--ignore-certificate-errors");
                option.AddArguments("--ignore-ssl-errors");
                Browser = new FirefoxDriver(iWoekDir, option);
            }
            Browser.Manage().Window.Maximize();
            Wait = new WebDriverWait(Browser, TimeSpan.FromSeconds(30));
            Browser.Navigate().GoToUrl("https://www.flickr.com/");
            Login login = new Login();

            login.LoginFlickr();
        }
Exemplo n.º 2
0
        public FirefoxOptions UseBrowserConfigurationForFirefox()
        {
            FirefoxProfile myProfile = new FirefoxProfileManager().GetProfile("default");

            if (myProfile == null)
            {
                throw new Exception("default firefox profile does not exist, please create it first.");
            }

            myProfile.AcceptUntrustedCertificates      = true;
            myProfile.AssumeUntrustedCertificateIssuer = true;
            myProfile.SetPreference("browser.cache.memory.enable", false);
            myProfile.SetPreference("browser.cache.offline.enable", false);
            myProfile.SetPreference("browser.cache.disk.enable", false);
            myProfile.SetPreference("network.http.use - cache", false);

            FirefoxOptions firefoxOptions = new FirefoxOptions();

            firefoxOptions.AddArguments("--headless");
            firefoxOptions.AddArguments("--window-size=1920,1080");
            firefoxOptions.LogLevel = FirefoxDriverLogLevel.Trace;
            firefoxOptions.Profile  = myProfile;

            return(firefoxOptions);
        }
Exemplo n.º 3
0
        private bool FirefoxEx(TimelineHandler handler)
        {
            try
            {
                string path = GetFirefoxInstallLocation();

                if (!IsSufficientVersion(path))
                {
                    _log.Warn("Firefox version is not sufficient. Exiting");
                    return(true);
                }

                FirefoxOptions options = new FirefoxOptions();
                options.AddArguments("--disable-infobars");
                if (handler.HandlerArgs != null &&
                    handler.HandlerArgs.ContainsKey("isheadless") &&
                    handler.HandlerArgs["isheadless"] == "true")
                {
                    options.AddArguments("--headless");
                }
                options.BrowserExecutableLocation = path;
                options.Profile = new FirefoxProfile();

                Driver = new FirefoxDriver(options);

                Driver.Navigate().GoToUrl(handler.Initial);

                if (handler.Loop)
                {
                    while (true)
                    {
                        if (Driver.CurrentWindowHandle == null)
                        {
                            throw new Exception("Firefox window handle not available");
                        }

                        ExecuteEvents(handler);
                    }
                }
                else
                {
                    ExecuteEvents(handler);
                }
            }
            catch (Exception e)
            {
                _log.Debug(e);
                return(false);
            }
            finally
            {
                ProcessManager.KillProcessAndChildrenByName(ProcessManager.ProcessNames.Firefox);
                ProcessManager.KillProcessAndChildrenByName(ProcessManager.ProcessNames.GeckoDriver);
            }

            return(true);
        }
Exemplo n.º 4
0
        public static DriverOptions DefaultOptions(bool headless)
        {
            var chromeOptions = new FirefoxOptions();

            chromeOptions.AddArguments(headless ? "headless" : string.Empty);
            chromeOptions.AddArguments("--no-sandbox");
            chromeOptions.AddArguments("--disable-dev-shm-usage");

            return(chromeOptions);
        }
Exemplo n.º 5
0
        private void ConfigureDriverOptions(FirefoxOptions options, IWebDriverOptions webDriverOptions)
        {
            if (webDriverOptions.Headless)
            {
                options.AddArgument("--headless");
            }

            // Apply user agent.

            FirefoxProfile profile = new FirefoxProfile {
                DeleteAfterUse = true
            };

            if (!string.IsNullOrEmpty(webDriverOptions.UserAgent))
            {
                profile.SetPreference("general.useragent.override", webDriverOptions.UserAgent);
            }

            // If the user specified a proxy, apply the proxy.

            if (!webDriverOptions.Proxy.IsEmpty())
            {
                string proxyAbsoluteUri = webDriverOptions.Proxy.ToProxyString();

                Proxy proxy = new Proxy {
                    HttpProxy = proxyAbsoluteUri,
                    SslProxy  = proxyAbsoluteUri
                };

                options.Proxy = proxy;
            }

            if (webDriverOptions.DisablePopUps)
            {
                profile.SetPreference("dom.popup_allowed_events", "");
            }

            options.Profile = profile;

            options.PageLoadStrategy = (OpenQA.Selenium.PageLoadStrategy)webDriverOptions.PageLoadStrategy;

            // Resize the window to a reasonable resolution so that viewport matches a conventional monitor viewport.

            options.AddArguments($"--width={webDriverOptions.WindowSize.Width}");
            options.AddArguments($"--height={webDriverOptions.WindowSize.Height}");

            // Disable the "navigator.webdriver" property.

            if (webDriverOptions.Stealth)
            {
                profile.SetPreference("dom.webdriver.enabled", false);
            }
        }
        /// <summary>
        /// Method to launch browser
        /// </summary>
        /// <param name="browser"></param>
        public void LaunchBrowser(string browser)
        {
            //Checking browser

            switch (browser.ToLower().Split('+')[0])
            {
            case "firefox":
                //      var ffOptions = new FirefoxOptions();
                //      ffOptions.BrowserExecutableLocation = @"C:\Program Files\Mozilla Firefox\firefox.exe";
                //  ffOptions.LogLevel = FirefoxDriverLogLevel.Default;
                //   ffOptions.Profile = new FirefoxProfile { AcceptUntrustedCertificates = true };
                //  var service = FirefoxDriverService.CreateDefaultService();

                FirefoxOptions FirefxOptions = new FirefoxOptions();

                if (browser.Contains("headless"))
                {
                    FirefxOptions.AddArguments("--headless");
                    FirefxOptions.AddArguments("disable-gpu");
                    FirefxOptions.AddArguments("window-size=1920,1080");
                }


                driver = new FirefoxDriver(FirefxOptions);

                break;

            case "chrome":
                ChromeOptions       ChrOptions = new ChromeOptions();
                ChromeDriverService service    = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));
                service.HideCommandPromptWindow = true;

                if (browser.Contains("headless"))
                {
                    ChrOptions.AddArgument("--headless");
                    ChrOptions.AddArguments("disable-gpu");
                    ChrOptions.AddArguments("window-size=1920,1080");
                }
                driver = new ChromeDriver(service, ChrOptions);
                break;

            default:

                break;
            }

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(30);
        }
Exemplo n.º 7
0
        private FirefoxDriver StartDriver()
        {
            FirefoxOptions ffo = new FirefoxOptions();

            ffo.AddArguments(new[] { "--private" });
            ffo.SetPreference("pageLoadStrategy", "eager");
            while (driver == null)
            {
                try
                {
                    driver = new FirefoxDriver(ffo);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
            driver.Url = "https://login.yahoo.com";

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

            var elem = wait.Until(ExpectedConditions.ElementToBeClickable((By.CssSelector("input.phone-no#login-username"))));;

            elem.SendKeys("*****@*****.**");
            //driver.FindElementById("login-signin").Click();
            return(driver);
        }
Exemplo n.º 8
0
        static int GetFreeBikes() //aktualnie wole rowery
        {
            const string url       = "https://www.veturilo.waw.pl/mapa-stacji/";
            int          freeBikes = 0;

            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("--headless");

            using (FirefoxDriver fDriver = new FirefoxDriver(options))
            {
                fDriver.Navigate().GoToUrl(url);

                var link = fDriver.FindElements(By.TagName("tr"));
                veturiloData.Add(link.Count() - 1); //odejmujemy nagłówek

                for (int i = 2; i <= link.Count() - 1; i++)
                {
                    freeBikes += int.Parse(fDriver.FindElement(By.XPath("//tr[" + i + "]/td[2]")).Text);
                }
                veturiloData.Add(freeBikes);

                fDriver.Close();
            }
            return(freeBikes);
        }
        public FirefoxFixture()
        {
            var options = new FirefoxOptions();

            options.AddArguments("--headless");
            Browser = new FirefoxDriver(options);
        }
Exemplo n.º 10
0
        public FirefoxOptions GautiFirefoxPradinesKonfiguracijas()
        {
            FirefoxOptions konfiguracijosFF = new FirefoxOptions();

            konfiguracijosFF.AddArguments("-headless");
            return(konfiguracijosFF);
        }
Exemplo n.º 11
0
        static List <int> GetBikesData() //webscrapping danych o rowerach veturilo
        {
            const string url      = "https://www.veturilo.waw.pl/mapa-stacji/";
            int          allBikes = 0;

            List <int> veturiloData = new List <int>(); //po kolei dane: ilość stacji, ilość rowerów

            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("--headless");

            using (FirefoxDriver fDriver = new FirefoxDriver(options))
            {
                fDriver.Navigate().GoToUrl(url);

                var link = fDriver.FindElements(By.TagName("tr"));
                veturiloData.Add(link.Count() - 1); //odejmujemy nagłówek

                for (int i = 2; i <= link.Count() - 1; i++)
                {
                    allBikes += int.Parse(fDriver.FindElement(By.XPath("//tr[" + i + "]/td[3]")).Text);
                }
                veturiloData.Add(allBikes);

                fDriver.Close();
            }
            return(veturiloData);
        }
Exemplo n.º 12
0
        private static FirefoxOptions GetFirefoxOptions()
        {
            FirefoxOptions optionsFirefox = new FirefoxOptions();

            optionsFirefox.AddArguments("");
            return(optionsFirefox);
        }
        public void SetupTest()
        {
            appURL = "https://mcw-todo-app.azurewebsites.net";
            // appURL = "http://localhost:8484";
            string driverLocation;

            string browser = "Chrome";

            switch (browser)
            {
            case "Firefox":
                FirefoxOptions opts = new FirefoxOptions();
                opts.AddArguments("--headless");
                driverLocation = Environment.GetEnvironmentVariable("GeckoWebDriver");
                driver         = driverLocation == null ? new FirefoxDriver(driverLocation, opts) : new FirefoxDriver(opts);
                break;

            case "IE":
                driverLocation = Environment.GetEnvironmentVariable("IEWebDriver");
                driver         = driverLocation == null ? new InternetExplorerDriver(driverLocation) : new InternetExplorerDriver();
                break;

            default:
                ChromeOptions options = new ChromeOptions();
                options.AddArguments("headless");
                driverLocation = Environment.GetEnvironmentVariable("ChromeWebDriver");
                driver         = driverLocation == null ? new ChromeDriver(options) : new ChromeDriver(driverLocation, options);
                break;
            }
        }
Exemplo n.º 14
0
        private static string scrapePublicLists()
        {
            FirefoxOptions options = new FirefoxOptions();
            options.AddArguments("--headless");
            string URL1 = "https://www.proxy-list.download/SOCKS4";
            string URL2 = "https://www.proxy-list.download/SOCKS5";

            using (var driver = new FirefoxDriver(options))
            {
                driver.Navigate().GoToUrl(URL1);
                Task.Delay(1000).Wait();

                string js = "var a = \"\";arr.forEach(function(t) {a += t.IP + \":\" + t.PORT + \"\\r\\n\"});return a;";
                IJavaScriptExecutor jsexec = (IJavaScriptExecutor)driver;
                string proxies = (string)jsexec.ExecuteScript(js);

                driver.Navigate().GoToUrl(URL2);
                Task.Delay(1000).Wait();

                jsexec = (IJavaScriptExecutor)driver;
                proxies += (string)jsexec.ExecuteScript(js);
                driver.Quit();
                return proxies;
            }
        }
Exemplo n.º 15
0
        public void ProfileGraphsTest()
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("--headless");

            using (var driver = _isHeadless ? new FirefoxDriver(options) : new FirefoxDriver())
            {
                Login(driver);

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

                IWebElement profileLink = wait.Until(ExpectedConditions.ElementToBeClickable(By.XPath("/html/body/nav/div/div[2]/form/ul/li[2]/a")));
                profileLink.Click();

                var comboBox = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[@id=\"chart-selection\"]")));
                Thread.Sleep(1000);
                new SelectElement(comboBox).SelectByText("Minutes Played per Team");
                Thread.Sleep(1000);
                new SelectElement(comboBox).SelectByText("Kill Death Ratio by Map");
                Thread.Sleep(1000);
                new SelectElement(comboBox).SelectByText("Kill Death Ratio by Team");
                Thread.Sleep(1000);
                new SelectElement(comboBox).SelectByText("Wins by Team");
                Thread.Sleep(1000);

                driver.Close();
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 初始化引擎
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        private FirefoxDriver LaunchFireFox(FirefoxOptions option)
        {
            var useEmbededBrowser = _config.GetValue <bool>("Driver:UseEmbededBrowser");

            var browserPath = useEmbededBrowser ? GetBrowserPath() : "";

            //folder containe geckodriver
            var geckodriverFullPath = GetGeckoDriverPath();
            var pathArray           = geckodriverFullPath.Split(',');

            //use embeded driver and geckodriver
            var fds = string.IsNullOrEmpty(geckodriverFullPath)
                ? FirefoxDriverService.CreateDefaultService()
                : FirefoxDriverService.CreateDefaultService(pathArray[0], pathArray[1]);

            if (!string.IsNullOrWhiteSpace(browserPath))
            {
                fds.FirefoxBinaryPath = browserPath;
            }


            var args = _config.GetSection("Driver:Argument").Get <List <string> >();

            //option.AddArgument("-headless");
            if (args != null && args.Count > 0)
            {
                option.AddArguments(args);
            }

            var driver = new FirefoxDriver(fds, option, TimeSpan.FromMinutes(1));

            return(driver);
        }
Exemplo n.º 17
0
        private static RemoteWebDriver StartFirefoxDriver(DriverSettings settings)
        {
            var profile = new FirefoxProfile(null, true);

            if (!string.IsNullOrEmpty(settings.Proxy))
            {
                profile.SetProxyPreferences(new Proxy {
                    HttpProxy = settings.Proxy
                });
            }
            settings.Extensions?.ForEach(ext => profile.AddExtension(ext.RelativeToBaseDirectory()));
            var options = new FirefoxOptions {
                Profile = profile, UseLegacyImplementation = false
            };

            settings.Capabilities?.ForEach(cap => options.AddAdditionalCapability(cap.Key, cap.Value));
            if (!string.IsNullOrEmpty(settings.BrowserBinaryPath))
            {
                options.BrowserExecutableLocation = settings.BrowserBinaryPath;
            }
            if (settings.CmdArgs != null)
            {
                options.AddArguments(settings.CmdArgs);
            }
            settings.ProfilePrefs?.ForEach(pref => options.SetPreference(pref.Key, (dynamic)pref.Value));
            return(new FirefoxDriver(options));
        }
Exemplo n.º 18
0
        private static IWebDriver GetFirefoxDriver()
        {
            FirefoxOptions firefoxOptions = new FirefoxOptions();

            firefoxOptions.AddArguments("--whitelisted-ips=\"\"");
            IWebDriver driver = null;

            try
            {
                driver = new RemoteWebDriver(
                    new Uri(ConfigurationManager.AppSettings["SELENIUM_GRID_URL"]),
                    firefoxOptions);
            }
            catch (WebException e)
            {
                if (e.Message.ToUpper().Contains("UNABLE TO CONNECT"))
                {
                    try
                    {
                        driver = new FirefoxDriver(Environment.GetEnvironmentVariable("GeckoWebDriver"), firefoxOptions);
                    }
                    catch (DriverServiceNotFoundException)
                    {
                        driver = new FirefoxDriver(firefoxOptions);
                    }
                }
            }
            return(driver);
        }
Exemplo n.º 19
0
        public static IWebDriver GetDriver(string browser)
        {
            if (driver == null)
            {
                switch (browser)
                {
                case "Firefox":
                {
                    FirefoxOptions options = new FirefoxOptions();
                    options.AddArguments("--start-fullscreen");
                    driver = new FirefoxDriver(options);
                    break;
                };

                default:
                {
                    ChromeOptions options = new ChromeOptions();
                    options.AddArguments("--start-fullscreen");
                    driver = new ChromeDriver(options);
                    break;
                }
                }
            }
            return(driver);
        }
Exemplo n.º 20
0
        static List <string> GetWeather() //webscrapping pogody
        {
            const string url = "https://pogoda.interia.pl/prognoza-szczegolowa-warszawa,cId,36917";

            List <string> weatherData = new List <string>(); //po kolei dane: temperatura, opis, jakość powietrzal, link do obrazka

            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("--headless");

            using (FirefoxDriver fDriver = new FirefoxDriver(options))
            {
                fDriver.Navigate().GoToUrl(url);

                weatherData.Add(fDriver.FindElement(By.XPath("//div[@class='weather-currently-temp-strict']")).Text);
                weatherData.Add(fDriver.FindElement(By.XPath("//li[@class='weather-currently-icon-description']")).Text);
                weatherData.Add(fDriver.FindElement(By.XPath("//div[@class='kind']/div[@class='value']")).Text);

                fDriver.Navigate().GoToUrl("https://pogoda.onet.pl/prognoza-pogody/warszawa-357732");
                weatherData.Add(fDriver.FindElement(By.XPath("//div[@class='mainParams']//div[@class='forecast']//span[@class='iconHolder']//img[@class='svg']")).GetAttribute("src"));

                fDriver.Close();
            }
            return(weatherData);
        }
Exemplo n.º 21
0
        public IWebDriver LoadFirefoxDriver(bool headless = false)
        {
            var driverService = FirefoxDriverService.CreateDefaultService(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            try
            {
                driverService.HideCommandPromptWindow = true;
                driverService.Host = "::1";

                var options = new FirefoxOptions();
                options.AddArgument("--disable-extensions");
                options.AddArgument("--disable-popup-blocking");
                options.AddArgument("--window-size=1920,1080");
                options.AddArguments("--disable-infobars");

                if (headless == true)
                {
                    options.AddArgument("headless");
                }

                var driver = new OpenQA.Selenium.Firefox.FirefoxDriver(driverService, options);
                driver.Manage().Window.Maximize();
                return(driver);
            }
            catch (WebDriverException we)
            {
                throw new WebDriverException(we.Message);
            }
        }
Exemplo n.º 22
0
        /// <summary>
        /// 初始化引擎
        /// </summary>
        /// <param name="option"></param>
        /// <returns></returns>
        private RemoteWebDriver LaunchFireFox(FirefoxOptions option)
        {
            // EngineType engineType = EngineType.Local;

            var engineType = _config.GetValue <EngineType>("Driver:Type");

            _logger.Info($"using driverType:{engineType}");

            var browserPath = engineType == EngineType.Embed ? GetBrowserPath() : "";

            //folder contain geckodriver
            var geckodriverFullPath = GetGeckoDriverPath();
            var pathArray           = geckodriverFullPath.Split(',');

            //use embed driver and geckodriver
            var fds = string.IsNullOrEmpty(geckodriverFullPath)
            ? FirefoxDriverService.CreateDefaultService()
            : FirefoxDriverService.CreateDefaultService(pathArray[0], pathArray[1]);

            if (!string.IsNullOrWhiteSpace(browserPath))
            {
                fds.FirefoxBinaryPath = browserPath;
            }


            var args = _config.GetSection("Driver:Argument").Get <List <string> >();

            //option.AddArgument("-headless");
            if (args != null && args.Count > 0)
            {
                option.AddArguments(args);
            }

            //hide add on or other log
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                Environment.SetEnvironmentVariable("BROWSER_LOGFILE", "NUL 2>&1");
            }


            RemoteWebDriver driver = null;

            switch (engineType)
            {
            case EngineType.Local:
            case EngineType.Embed:
                driver = new FirefoxDriver(fds, option, TimeSpan.FromMinutes(1));
                break;

            case EngineType.Remote:
                //var uri = "http://10.252.90.122:4444/hub";
                var uri            = _config.GetValue <string>("Driver:EndPoint");
                var capabilities   = option.ToCapabilities();
                var commandTimeout = TimeSpan.FromSeconds(60);
                driver = new RemoteWebDriver(new Uri(uri), capabilities, commandTimeout);
                break;
            }

            return(driver);
        }
Exemplo n.º 23
0
        public void SetUp(string Browser, string url)
        {
            optFireFox.AddArguments("--ignore-certificate-errors", "--start-maximized", "--disabl-web-security", "--handless");
            optChrome.AddArguments("--ignore-certificate-errors", "--no-sandbox", "--start-maximized", "--disable-web-security", "--handless");
            optIE.IntroduceInstabilityByIgnoringProtectedModeSettings = true;

            switch (Browser)
            {
            case "Chrome":
                _driver = new ChromeDriver(PathDriverGet.PathDriver(), optChrome);
                _driver.Navigate().GoToUrl(url);
                _driver.Manage().Window.Maximize();
                break;

            case "Firefox":
                _driver = new FirefoxDriver(PathDriverGet.PathDriver(), optFireFox);
                _driver.Navigate().GoToUrl(url);
                _driver.Manage().Window.Maximize();
                break;

            case "IE":
                _driver = new InternetExplorerDriver(PathDriverGet.PathDriver(), optIE);
                _driver.Navigate().GoToUrl(url);
                _driver.Manage().Window.Maximize();
                break;

            default:
                throw new NotSupportedException("Not supported browser");
            }
        }
Exemplo n.º 24
0
        public FirefoxDriver GetFirefoxDriver()
        {
            if (_firefoxDriver != null)
            {
                return(_firefoxDriver);
            }

            //profile.SetPreference() braucht zusätzliche Encodings, sonst gibt es eine Exception
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            //https://stackoverflow.com/questions/46836472/selenium-with-net-core-performance-impact-multiple-threads-in-iwebelement
            var driverPath = $@"{AppDomain.CurrentDomain.BaseDirectory}";
            var service    = FirefoxDriverService.CreateDefaultService(driverPath);

            var options = new FirefoxOptions();

            options.AddArguments("--headless");

            var profile = new FirefoxProfile();

            profile.SetPreference("intl.accept_languages", "de-de");
            profile.WriteToDisk();
            options.Profile = profile;

            _firefoxDriver = new FirefoxDriver(service, options);
            FixDriverCommandExecutionDelay(_firefoxDriver);

            return(_firefoxDriver);
        }
Exemplo n.º 25
0
        private FirefoxOptions CreateOptions()
        {
            var options = new FirefoxOptions();

            if (BrowserSettings.Settings.IsRemoteRun())
            {
                options.AddAdditionalCapability("version", BrowserSettings.Settings.Remote.Version ?? Constants.DEFAULT_VERSION, true);
                options.AddAdditionalCapability("enableVNC", true, true);
                options.AddAdditionalCapability("platform", BrowserSettings.Settings.Remote.Platform ?? Constants.DEFAULT_PLATFORM, true);
                options.AddAdditionalCapability("name", BrowserSettings.Settings.Remote.Project ?? Constants.DEFAULT_PROJECT, true);
            }

            if (BrowserSettings.Settings.IsOptions())
            {
                options.AddArguments(BrowserSettings.Settings.Options);
            }

            if (!BrowserSettings.Settings.IsBinaryPath())
            {
                options.BrowserExecutableLocation = BrowserSettings.Settings.BinaryLocation;
            }

            if (BrowserSettings.Settings.CheckCapability())
            {
                options.AddCapabilities(BrowserSettings.Settings.Capabilities);
            }

            return(options);
        }
        public IWebDriver GetBrowser(IApplicationSource applicationSource)
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments(applicationSource.GetBrowserOptions());
            return(new FirefoxDriver(options));
        }
Exemplo n.º 27
0
        /// <summary>
        /// Fetch the download link of the desired update by using the Selenium Firefox driver (a Firefox installation in the default directory is needed).
        /// </summary>
        /// <param name="searchUrl">Url of the starting website.</param>
        /// <param name="htmlID">Unique HTML ID of the specific update (e.g. 26896846-497d-4755-893a-6870f72ddcf4). This is only exposed in the HTML source code, however it is usable as a search parameter for the Microsoft Update Catalog</param>
        /// <returns>Direct download link to the specific update.</returns>
        private string FetchDownloadLinkFirefox(string searchUrl, string htmlID)
        {
            FirefoxDriverService driverService = FirefoxDriverService.CreateDefaultService();

            driverService.HideCommandPromptWindow = true;
            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("-headless");
            IWebDriver driver = new FirefoxDriver(driverService, options, TimeSpan.FromSeconds(10));

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
            driver.Navigate().GoToUrl(searchUrl);
            IWebElement       test              = driver.FindElement(By.XPath($"//input[@id='{htmlID}' and @value='Download']"));
            PopupWindowFinder finder            = new PopupWindowFinder(driver);
            string            popupWindowHandle = finder.Click(test);

            driver.SwitchTo().Window(popupWindowHandle);
            ReadOnlyCollection <IWebElement> downloadLinkElements = driver.FindElements(By.PartialLinkText(""));

            foreach (IWebElement downloadLinkElement in downloadLinkElements)
            {
                string downloadLink = downloadLinkElement.GetAttribute("href");
                if (downloadLink.EndsWith(".msu"))
                {
                    driver.Quit();
                    return(downloadLink);
                }
            }

            return(null);
        }
Exemplo n.º 28
0
        static void Main(string[] args)
        {
            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("--headless");

            FirefoxDriver driver = new FirefoxDriver(Environment.CurrentDirectory, options);

            //Console.WriteLine("Program running. Enter: Ctrl + C to exit program");
            //while(true)
            //{
            //    if (checkPage(driver, "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3070", "/html/body/app-root/product/div[1]/div[1]/div[2]/div/product-details/div/div/div/div[3]/div[2]/div[2]/div[2]/a", "Notify Me")
            //        || checkPage(driver, "https://www.bestbuy.com/site/searchpage.jsp?st=rtx+3070&_dyncharset=UTF-8&_dynSessConf=&id=pcat17071&type=page&sc=Global&cp=1&nrp=&sp=&qp=&list=n&af=true&iht=y&usc=All+Categories&ks=960&keys=keys", "/html/body/div[4]/main/div[10]/div/div/div/div/div/div/div[2]/div[2]/div[5]/div/div/div/div[6]/ol/li[2]/div/div/div/div/div/div[2]/div[2]/div[3]/div/div/div/div/div/button", "Coming Soon"))
            //        break;
            //}
            //uncomment in final product
            //SendEmail("*****@*****.**", "BACK IN STOCK", "BACK IN STOCK");

            string[] websites   = { "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3070", "https://www.bestbuy.com/site/searchpage.jsp?st=rtx+3070&_dyncharset=UTF-8&_dynSessConf=&id=pcat17071&type=page&sc=Global&cp=1&nrp=&sp=&qp=&list=n&af=true&iht=y&usc=All+Categories&ks=960&keys=keys" };
            string[] xpaths     = { "/html/body/app-root/product/div[1]/div[1]/div[2]/div/product-details/div/div/div/div[3]/div[2]/div[2]/div[2]/a", "/html/body/div[4]/main/div[10]/div/div/div/div/div/div/div[2]/div[2]/div[5]/div/div/div/div[6]/ol/li[2]/div/div/div/div/div/div[2]/div[2]/div[3]/div/div/div/div/div/button" };
            string[] textMatchs = { "Notify Me", "Coming Soon" };
            string[] classes    = { "featured-buy-link", "btn-disabled" };

            checkPageClasses(driver, websites, classes, textMatchs, 2);
            //checkPageXPaths(driver, websites, xpaths, textMatchs, 2);
            //checkPageTest(driver, "https://www.nvidia.com/en-us/shop/geforce/?page=1&limit=9&locale=en-us&search=3070", "notify-me-btn", "notify me");
        }
Exemplo n.º 29
0
    public static IWebDriver Gecko()
    {
        FirefoxOptions geckoOptions = new FirefoxOptions();

        geckoOptions.AddArguments(new List <string> {
            "-headless",
            "-private",
            //"--blink-settings=imagesEnabled=false",
            //"-test-type",
            //"-window-size=1920,1080",
            //"-no-sandbox",
            //"-disable-plugins",
            //"-disable-cache",
            //"-disable-keep-alive",
            //"-disable-hang-monitor",
            //"-disable-web-security",
            //"-disable-extensions",
            //"-disable-application-cache",
            //"-disable-popup-blocking",
            //"-disable-default-apps",
            //"-disable-dev-shm-usage",
            //"-disable-gpu",
            //"-ignore-certificate-errors"
        });

        FirefoxDriverService geckoDriverService = FirefoxDriverService.CreateDefaultService();

        geckoDriverService.SuppressInitialDiagnosticInformation = true;
        geckoDriverService.HideCommandPromptWindow = true;
        return(new FirefoxDriver(geckoDriverService, geckoOptions));
    }
Exemplo n.º 30
0
        static void GetDownloadLinks() //funkcja używająca selenium w celu pobrania danych.
        {
            const string bikeDatabase = "http://greenelephant.pl/shiny/rowery/";

            FirefoxOptions options = new FirefoxOptions();

            options.AddArguments("--headless");

            using (FirefoxDriver fDriver = new FirefoxDriver(options)) //do webscrappingu korzystamy z przeglądarki firefox
            {
                fDriver.Navigate().GoToUrl(bikeDatabase);

                while (true)
                {
                    try
                    {
                        fDriver.FindElement(By.XPath("//span[contains(text(),'Marsa')]"));
                        break;
                    }
                    catch { }
                    Thread.Sleep(1000);
                }

                foreach (string x in locations)
                {
                    fDriver.FindElement(By.XPath("//span[contains(text(),'" + x + "')]")).Click();
                }

                string downloadLink = fDriver.FindElement(By.XPath("//a[@id='eksport']")).GetAttribute("href");
                GetDataFile(downloadLink, path + "data.txt");
                fDriver.Close();
            }
        }