Beispiel #1
0
        /// <summary>
        /// Método responsável pela pesquisa das leis do estado de São Paulo
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="ano"></param>
        /// <param name="hide"></param>
        public void PesquisaSP(string webDriver, int ano, bool hide)
        {
            // Criação do IwebDriver
            IWebDriver driver;
            // Lista que armazenará os links dos documentos
            List <string> listaDocumentos = new List <string>();
            // Booleano para auxiliar nas pesqusias
            bool continuar = true;
            // Coleção de Matchs, armazenará o resultado das Expressões Regulares
            MatchCollection Documentos;
            // Lista contendo os dados das leis extraídas
            List <Lei> leis = new List <Lei>();

            // If para identificar qual webdriver será usado, Chrome ou Phantom
            if (webDriver.Equals("Chrome"))
            {
                var serviceC = ChromeDriverService.CreateDefaultService();
                serviceC.HideCommandPromptWindow = hide;
                driver = new ChromeDriver(serviceC);
            }
            else if (webDriver.Equals("Phantom"))
            {
                var serviceP = PhantomJSDriverService.CreateDefaultService();
                serviceP.HideCommandPromptWindow = hide;
                driver = new PhantomJSDriver(serviceP);
            }
            else
            {
                return;
            }

            // Iniciando o acesso ao site Legislativo
            driver.Navigate().GoToUrl("http://www.legislacao.sp.gov.br/legislacao/dg280202.nsf/Leis?OpenView");

            // Busca do ano que será efetuada a pesquisa
            driver.FindElements(By.TagName("img")).FirstOrDefault(c => c.GetAttribute("alt").Contains(ano.ToString())).Click();

            // Do-While usado para percorrer todos os documentos do ano
            // Enquanto existir documento, ele continuará a paginação na busca de mais documentos
            do
            {
                // Armazena a lista de Matches com os documentos encontrados na página
                Documentos = Regex.Matches(driver.PageSource, @"href=\""(?<linkDoc>\/legislacao\/\S+?OpenDocument)\""", RegexOptions.Compiled | RegexOptions.IgnoreCase);

                // Foreach percorrendo toda a lista de Matches e adicionando o link do documento no listaDocumentos
                foreach (Match doc in Documentos)
                {
                    listaDocumentos.Add(doc.Groups["linkDoc"].Value);
                }

                // Compara se terminou os documentos, caso contrário, vá para a outra página e continue a pesquisa.
                if (Documentos.Count == 0)
                {
                    continuar = false;
                }
                else
                {
                    driver.FindElement(By.Id("RetângulodePontodeAcesso41")).Click();
                }
            } while (continuar);

            // For para percorrer os documentos encontrados e adicionar na lista de Leis
            // o For está limitado a apenas 10 documentos, para que não demore ao nosso retorno, mas pode ser ...
            // ... limitado ao tamanho total das leis encontradas trocando o valor "10" por "listaDocumentos.Count"
            for (int i = 0; i < 10; i++)
            {
                // Istancia a entidade Lei
                Lei lei = new Lei();

                driver.Navigate().GoToUrl(siteSP + listaDocumentos[i]);

                // Criamos 3 variáveis para nos auxliar, um Match, um DateTime e um string, ele verificará o retorno do site e depois irá inserir na nossa entidade
                Match    Titulo = Regex.Match(driver.PageSource, @">(?<titulo>Lei\s*n.\s*\d.*?de\s+(?<data>\d+\s+de\s*\S+\s*de\s*\d+))<", RegexOptions.Compiled | RegexOptions.IgnoreCase);
                DateTime data   = new DateTime();
                string   texto  = string.Empty;

                // Pegamos a data da lei e armazenamos na variável auxiliar "data"
                DateTime.TryParse(Titulo.Groups["data"].Value.Trim(), out data);

                // Pegamos o texto da lei, tratamos e armazenamos na variável auxiliar "texto"
                texto = Regex.Replace(driver.PageSource, @"<.*?>", "", RegexOptions.Compiled | RegexOptions.Singleline);
                texto = Regex.Match(texto, @"(?<texto>GOVERNO\s+DO\s+ESTADO.+?)\d+\.doc\s*$", RegexOptions.Singleline | RegexOptions.Multiline).Groups["texto"].Value.Trim();

                // Inserimos os dados na nossa entidade
                lei.Titulo = Titulo.Groups["titulo"].Value.Trim();
                lei.Data   = data;
                lei.Texto  = texto;

                // Inserimos essa entidade na nossa lista de Leis
                leis.Add(lei);
            }

            // Quando finalizar a extração, fechamos o IWebDriver e exibimos nosso resultado na tela através do DataGridView
            driver.Quit();
            dataGridView1.DataSource = leis;
        }
Beispiel #2
0
        public static IWebDriver CreateWebDriver(BrowserOptions options)
        {
            IWebDriver driver;

            switch (options.BrowserType)
            {
            case BrowserType.Chrome:
                var chromeService = ChromeDriverService.CreateDefaultService();
                chromeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new ChromeDriver(chromeService, options.ToChrome());

                /*
                 * // chrome headless driver
                 * ChromeOptions cOption = new ChromeOptions();
                 * cOption.AddArgument("--headless");
                 * driver = new ChromeDriver(cOption);
                 */
                break;

            case BrowserType.IE:
                var ieService = InternetExplorerDriverService.CreateDefaultService();
                ieService.SuppressInitialDiagnosticInformation = options.HideDiagnosticWindow;
                driver = new InternetExplorerDriver(ieService, options.ToInternetExplorer(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Firefox:
                var ffService = FirefoxDriverService.CreateDefaultService();
                ffService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new FirefoxDriver(ffService);
                driver.Manage().Timeouts().ImplicitWait = new TimeSpan(0, 0, 5);
                break;

            case BrowserType.PhantomJs:
                var pOptions = new PhantomJSOptions();

                pOptions.AddAdditionalCapability(
                    "phantomjs.page.settings.userAgent",
                    "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36");
                pOptions.AddAdditionalCapability("phantomjs.page.settings.resourceTimeout", "5000");

                var pService = PhantomJSDriverService.CreateDefaultService(options.DriversPath);
                pService.AddArgument("--ignore-ssl-errors=true");

                driver = new PhantomJSDriver(pService, pOptions, TimeSpan.FromMinutes(5));
                driver.Manage().Window.Size = new System.Drawing.Size(1280, 1024);
                break;

            case BrowserType.Edge:
                var edgeService = EdgeDriverService.CreateDefaultService();
                edgeService.HideCommandPromptWindow = options.HideDiagnosticWindow;
                driver = new EdgeDriver(edgeService, options.ToEdge(), TimeSpan.FromMinutes(20));
                break;

            case BrowserType.Remote:
                // make sure selenium standalone server is running
                DesiredCapabilities capabilities = DesiredCapabilities.HtmlUnit();
                driver = new RemoteWebDriver(capabilities);
                break;

            default:
                throw new InvalidOperationException(
                          $"The browser type '{options.BrowserType}' is not recognized.");
            }

            driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 5, 0);             //options.PageLoadTimeout;

            if (options.StartMaximized && options.BrowserType != BrowserType.Chrome) //Handle Chrome in the Browser Options
            {
                driver.Manage().Window.Maximize();
            }

            if (options.FireEvents || options.EnableRecording)
            {
                // Wrap the newly created driver.
                driver = new EventFiringWebDriver(driver);
            }

            return(driver);
        }
        public IWebDriver CreateDriver(Browser browser)
        {
            ProxyService.GetNewProxyIp();
            _proxyServer = new ProxyServer();
            var explicitEndPoint = new ExplicitProxyEndPoint(System.Net.IPAddress.Any, 18882, false);

            _proxyServer.CertificateManager.TrustRootCertificate(true);
            _proxyServer.AddEndPoint(explicitEndPoint);
            _proxyServer.Start();
            _proxyServer.SetAsSystemHttpProxy(explicitEndPoint);
            _proxyServer.SetAsSystemHttpsProxy(explicitEndPoint);
            _proxyServer.UpStreamHttpProxy = new ExternalProxy {
                HostName = ProxyService.CurrentProxyIpHost, Port = ProxyService.CurrentProxyIpPort
            };
            _proxyServer.UpStreamHttpsProxy = new ExternalProxy {
                HostName = ProxyService.CurrentProxyIpHost, Port = ProxyService.CurrentProxyIpPort
            };

            var proxyChangerTimer = new Timer();

            proxyChangerTimer.Elapsed += ChangeProxyEventHandler;
            proxyChangerTimer.Interval = SecondsToRefreshProxy * 1000;
            proxyChangerTimer.Enabled  = true;

            var proxy = new Proxy
            {
                HttpProxy = "localhost:18882",
                SslProxy  = "localhost:18882",
                FtpProxy  = "localhost:18882",
            };

            IWebDriver webDriver;

            switch (browser)
            {
            case Browser.Chrome:

                var chromeOptions = new ChromeOptions
                {
                    Proxy = proxy
                };
                var chromeDriverService = ChromeDriverService.CreateDefaultService(_assemblyFolder);
                webDriver = new ChromeDriver(chromeDriverService, chromeOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Chrome.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Chrome.ScriptTimeout);
                break;

            case Browser.Firefox:
                var firefoxOptions = new FirefoxOptions()
                {
                    Proxy = proxy
                };
                webDriver = new FirefoxDriver(Environment.CurrentDirectory, firefoxOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Firefox.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Firefox.ScriptTimeout);
                break;

            case Browser.Edge:
                var edgeOptions = new EdgeOptions()
                {
                    Proxy = proxy
                };
                webDriver = new EdgeDriver(Environment.CurrentDirectory, edgeOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Edge.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().Edge.ScriptTimeout);
                break;

            case Browser.InternetExplorer:
                var ieOptions = new InternetExplorerOptions()
                {
                    Proxy = proxy
                };
                webDriver = new InternetExplorerDriver(Environment.CurrentDirectory, ieOptions);
                webDriver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().InternetExplorer.PageLoadTimeout);
                webDriver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(ConfigurationService.Instance.GetWebSettings().InternetExplorer.ScriptTimeout);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(browser), browser, null);
            }

            return(webDriver);
        }
Beispiel #4
0
        /// <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
                    };
                    var internetExplorerDriverService = InternetExplorerDriverService.CreateDefaultService();
                    internetExplorerDriverService.HideCommandPromptWindow = true;
                    driver = new InternetExplorerDriver(internetExplorerDriverService, explorerOptions);
                    break;

                case BrowserType.FireFox:
                    driver = GetFireFoxDriver(browserFactoryConfiguration);
                    break;

                case BrowserType.Chrome:
                    var chromeOptions = new ChromeOptions {
                        LeaveBrowserRunning = false
                    };
                    var chromeDriverService = ChromeDriverService.CreateDefaultService();
                    chromeDriverService.HideCommandPromptWindow = true;

                    if (browserFactoryConfiguration.EnsureCleanSession)
                    {
                        chromeOptions.AddArgument("--incognito");
                    }

                    driver = new ChromeDriver(chromeDriverService, chromeOptions);
                    break;

                case BrowserType.PhantomJS:
                    var phantomJsDriverService = PhantomJSDriverService.CreateDefaultService();
                    phantomJsDriverService.HideCommandPromptWindow = true;
                    driver = new PhantomJSDriver(phantomJsDriverService);
                    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);
        }
        public void OpenonlyFB(string userFB, string passFB, string browser)
        {
            try
            {
                ChromeOptions options = new ChromeOptions();

                if (!Directory.Exists(ProfileFolderPath))
                {
                    Directory.CreateDirectory(ProfileFolderPath);
                }

                if (Directory.Exists(ProfileFolderPath))
                {
                    //int nameCount = 0;

                    options.AddArguments("user-data-dir=" + ProfileFolderPath + "\\" + userFB);
                }


                //driver = new ChromeDriver(options);

                //code hide cmd.exe
                ChromeDriverService service = ChromeDriverService.CreateDefaultService();
                service.HideCommandPromptWindow = true;

                driver = new ChromeDriver(service, options);

                if (browser == "1")
                {
                    driver.Manage().Window.Position = new Point(0, 0);
                    driver.Manage().Window.Size = new Size(640, 1080);
                }
                else
                {
                    if (browser == "2")
                    {
                        driver.Manage().Window.Position = new Point(640, 0);
                        driver.Manage().Window.Size = new Size(640, 1080);
                    }
                    else
                    {
                        if (browser == "3")
                        {
                            driver.Manage().Window.Position = new Point(1280, 0);
                            driver.Manage().Window.Size = new Size(640, 1080);
                        }
                    }
                }


                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(WaitLoadTime);
                driver.Url = "http://fb.com/";


                driver.Navigate();
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(WaitLoadTime);

                //CheckTurnofFormControledAndRestore(browser);
                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(WaitLoadTime);
                Thread.Sleep(WaitStepTime);
                driver.Navigate().Refresh();
                Thread.Sleep(WaitStepTime);



                LoginFacebook(userFB, passFB);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Cann't open!!!");
            }
        }
Beispiel #6
0
        public async Task GetCityGeometrics()
        {
            var cities = GetAllCities();
            var citiesgeoMetricsList = new List <CityGeometricDto>();
            await Task.Run(() => {
                ParallelOptions po        = new ParallelOptions();
                po.MaxDegreeOfParallelism = 7;
                Parallel.For(0, cities.Count, po, i => {
                    ChromeDriverService chromeDriverService     = ChromeDriverService.CreateDefaultService();
                    chromeDriverService.HideCommandPromptWindow = true;
                    ChromeOptions options = new ChromeOptions();
                    options.AddArgument("--headless");
                    var driver     = new ChromeDriver(chromeDriverService, options, TimeSpan.FromSeconds(120));
                    var currentRun = new RunDto
                    {
                        StartedAt = DateTime.Now
                    };
                    driver.Navigate().GoToUrl("https://www.gismeteo.ru/" + cities[i].Url + "10-days/");
                    _logger.LogInformation("https://www.gismeteo.ru/" + cities[i].Url + "10-days/");
                    citiesgeoMetricsList.Add(new CityGeometricDto
                    {
                        CityId     = cities[i].Id,
                        Geometrics = ParseData(driver).Result,
                        Run        = currentRun
                    });
                    currentRun.EndedAt = DateTime.Now;
                    Exit(driver, chromeDriverService);
                });
            });

            foreach (var city in citiesgeoMetricsList)
            {
                var newRun = new Run
                {
                    Id        = Guid.NewGuid(),
                    StartedAt = city.Run.StartedAt,
                    EndedAt   = city.Run.EndedAt,
                    FkCity    = city.CityId
                };
                Create(newRun);
                foreach (var gm in city.Geometrics)
                {
                    Create(new GeoMetric
                    {
                        Id        = Guid.NewGuid(),
                        DayName   = gm.DayName,
                        DayNumber = gm.DayNumber,
                        MaxTempC  = gm.MaxTempC,
                        MaxTempF  = gm.MaxTempF,
                        MinTempC  = gm.MinTempC,
                        MinTempF  = gm.MinTempF,
                        WindMs    = gm.WindMs,
                        MiH       = gm.MiH,
                        KmH       = gm.KmH,
                        Prec      = gm.Prec,
                        FkRunId   = newRun.Id
                    });
                }
            }
            Save();
        }
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new StockContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <StockContext> >()))
            {
                if (context.Stock.Any())
                {
                    return;   // DB has been seeded
                }



                ChromeOptions options = new ChromeOptions();
                options.AddArgument("no-sandbox");


                IWebDriver driver = new ChromeDriver(ChromeDriverService.CreateDefaultService(), options, TimeSpan.FromMinutes(3));
                driver.Manage().Timeouts().PageLoad.Add(TimeSpan.FromSeconds(1200));

                driver.Navigate().GoToUrl("https://finance.yahoo.com/");

                driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(1200);

                WebDriverWait waitLogin = new WebDriverWait(driver, TimeSpan.FromMinutes(30));
                waitLogin.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id("uh-signedin")));

                driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(10);


                IWebElement loginButton = driver.FindElement(By.Id("uh-signedin"));
                loginButton.Click();

                WebDriverWait waitEnterUsername = new WebDriverWait(driver, TimeSpan.FromMinutes(50));
                waitEnterUsername.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id("login-username")));

                IWebElement userName = driver.FindElement(By.Id("login-username"));

                userName.SendKeys("*****@*****.**");
                userName.SendKeys(Keys.Enter);

                WebDriverWait waitEnterPassword = new WebDriverWait(driver, TimeSpan.FromMinutes(50));
                waitEnterPassword.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.Id("login-passwd")));
                IWebElement password = driver.FindElement(By.Id("login-passwd"));

                password.SendKeys("Soccer_1995");
                password.SendKeys(Keys.Enter);

                driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(10);

                driver.Navigate().GoToUrl("https://finance.yahoo.com/portfolio/p_0/view/v1");

                driver.Manage().Timeouts().PageLoad = TimeSpan.FromMinutes(10);

                WebDriverWait waitDataTable = new WebDriverWait(driver, TimeSpan.FromMinutes(50));
                waitDataTable.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementExists(By.XPath("//tr")));

                IWebElement        stockTable = driver.FindElement(By.XPath("//tbody"));
                List <IWebElement> stocks     = driver.FindElements(By.XPath("//tr")).ToList();

                List <IWebElement> rows = stockTable.FindElements(By.XPath("//tr")).ToList();
                int rowsCount           = rows.Count;



                for (int row = 1; row < rowsCount; row++)
                {
                    List <IWebElement> cells = rows.ElementAt(row).FindElements(By.TagName("td")).ToList();
                    int cellsCount           = cells.Count;



                    string SymbolData = cells.ElementAt(0).Text;
                    //Console.WriteLine("Symbol: " + SymbolData);
                    string LastPriceData = cells.ElementAt(1).Text;
                    //Console.WriteLine("Last Price: " + LastPriceData);
                    string ChangeData = cells.ElementAt(2).Text;
                    //Console.WriteLine("Change: " + ChangeData);
                    string ChangeRateData = cells.ElementAt(3).Text;
                    //Console.WriteLine("Change Rate: " + ChangeRateData);
                    string CurrencyData = cells.ElementAt(4).Text;
                    //Console.WriteLine("Currency: " + CurrencyData);
                    string MarketTimeData = cells.ElementAt(5).Text;
                    //Console.WriteLine("Market Time: " + MarketTimeData);
                    string VolumeData = cells.ElementAt(6).Text;
                    //Console.WriteLine("Volume: " + VolumeData);
                    string ShareData = cells.ElementAt(7).Text;
                    //Console.WriteLine("Shares: " + ShareData);
                    string AverageVolumeData = cells.ElementAt(8).Text;
                    //Console.WriteLine("Avg Vol Data: " + AverageVolumeData);
                    string MarketCapData = cells.ElementAt(12).Text;
                    //Console.WriteLine("Market Cap: " + MarketCapData);
                    // Look for any movies.
                    if (context.Stock.Any())
                    {
                        return;    // DB has been seeded
                    }

                    context.Stock.AddRange(
                        new Stocks
                    {
                        Symbol        = SymbolData,
                        LastPrice     = LastPriceData,
                        Change        = ChangeData,
                        ChangeRate    = ChangeRateData,
                        Currency      = CurrencyData,
                        MarketTime    = MarketTimeData,
                        Volume        = VolumeData,
                        ShareData     = ShareData,
                        AverageVolume = AverageVolumeData,
                        MarketCapData = MarketCapData
                    }
                        );
                    context.SaveChanges();
                }
            }
        }
 public ChromeDriverExtended(ChromeDriverService service, ChromeOptions options) : base(service, options)
 {
     InitializeSendCommand();
 }
        /// <summary>
        /// Instantiates a RemoteWebDriver instance based on the browser passed to this method. Opens the browser and maximizes its window.
        /// </summary>
        /// <param name="browser">The browser to get instantiate the Web Driver for.</param>
        /// <param name="browserProfilePath">The folder path to the browser user profile to use with the browser.</param>
        /// <returns>The RemoteWebDriver of the browser passed in to the method.</returns>
        public static RemoteWebDriver CreateDriverAndMaximize(string browser, bool clearBrowserCache, bool enableVerboseLogging = false, string browserProfilePath = "", List <string> extensionPaths = null, int port = 17556, string hostName = "localhost")
        {
            // Create a webdriver for the respective browser, depending on what we're testing.
            RemoteWebDriver driver = null;

            _browser = browser.ToLowerInvariant();

            switch (browser)
            {
            case "opera":
            case "operabeta":
                OperaOptions oOption = new OperaOptions();
                oOption.AddArgument("--disable-popup-blocking");
                oOption.AddArgument("--power-save-mode=on");
                // TODO: This shouldn't be a hardcoded path, but Opera appeared to need this speficied directly to run well
                oOption.BinaryLocation = @"C:\Program Files (x86)\Opera\launcher.exe";
                if (browser == "operabeta")
                {
                    // TODO: Ideally, this code would look inside the Opera beta folder for opera.exe
                    // rather than depending on flaky hard-coded version in directory
                    oOption.BinaryLocation = @"C:\Program Files (x86)\Opera beta\38.0.2220.25\opera.exe";
                }
                ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
                driver = new OperaDriver(oOption);
                break;

            case "firefox":
                ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
                driver = new FirefoxDriver();
                break;

            case "chrome":
                ChromeOptions option = new ChromeOptions();
                option.AddUserProfilePreference("profile.default_content_setting_values.notifications", 1);
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService();
                if (enableVerboseLogging)
                {
                    chromeDriverService.EnableVerboseLogging = true;
                }

                if (!string.IsNullOrEmpty(browserProfilePath))
                {
                    option.AddArgument("--user-data-dir=" + browserProfilePath);
                }

                ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
                driver = new ChromeDriver(chromeDriverService, option);
                break;

            default:
                EdgeOptions       edgeOptions       = new EdgeOptions();
                EdgeDriverService edgeDriverService = null;

                if (extensionPaths != null && extensionPaths.Count != 0)
                {
                    // Create the extensionPaths capability object
                    edgeOptions.AddAdditionalCapability("extensionPaths", extensionPaths);
                    foreach (var path in extensionPaths)
                    {
                        Logger.LogWriteLine($"Sideloading extension(s) from {path}");
                    }
                }

                if (hostName.Equals("localhost", StringComparison.InvariantCultureIgnoreCase))
                {
                    // Using localhost so create a local EdgeDriverService and instantiate an EdgeDriver object with it.
                    // We have to use EdgeDriver here instead of RemoteWebDriver because we need a
                    // DriverServiceCommandExecutor object which EdgeDriver creates when instantiated

                    edgeDriverService = EdgeDriverService.CreateDefaultService();
                    if (enableVerboseLogging)
                    {
                        edgeDriverService.UseVerboseLogging = true;
                    }

                    _port     = edgeDriverService.Port;
                    _hostName = hostName;

                    Logger.LogWriteLine($"  Instantiating EdgeDriver object for local execution - Host: {_hostName}  Port: {_port}");
                    ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
                    driver = new EdgeDriver(edgeDriverService, edgeOptions);
                }
                else
                {
                    // Using a different host name.
                    // We will make the assumption that this host name is the host of a remote webdriver instance.
                    // We have to use RemoteWebDriver here since it is capable of being instantiated without automatically
                    // opening a local MicrosoftWebDriver.exe instance (EdgeDriver automatically launches a local process with
                    // MicrosoftWebDriver.exe).

                    _port     = port;
                    _hostName = hostName;
                    var remoteUri = new Uri("http://" + _hostName + ":" + _port + "/");

                    Logger.LogWriteLine($"  Instantiating RemoteWebDriver object for remote execution - Host: {_hostName}  Port: {_port}");
                    ScenarioEventSourceProvider.EventLog.LaunchWebDriver(browser);
                    driver = new RemoteWebDriver(remoteUri, edgeOptions.ToCapabilities());
                }

                driver.Wait(2);

                if (clearBrowserCache)
                {
                    Logger.LogWriteLine("   Clearing Edge browser cache...");
                    ScenarioEventSourceProvider.EventLog.ClearEdgeBrowserCacheStart();
                    // Warning: this blows away all Microsoft Edge data, including bookmarks, cookies, passwords, etc
                    HttpClient client = new HttpClient();
                    client.DeleteAsync($"http://{_hostName}:{_port}/session/{driver.SessionId}/ms/history").Wait();
                    ScenarioEventSourceProvider.EventLog.ClearEdgeBrowserCacheStop();
                }

                _edgeBrowserBuildNumber = GetEdgeBuildNumber(driver);
                Logger.LogWriteLine($"   Browser Version - MicrosoftEdge Build Version: {_edgeBrowserBuildNumber}");

                _edgeWebDriverBuildNumber = GetEdgeWebDriverVersion(driver);
                Logger.LogWriteLine($"   WebDriver Server Version - MicrosoftWebDriver.exe File Version: {_edgeWebDriverBuildNumber}");

                break;
            }

            ScenarioEventSourceProvider.EventLog.MaximizeBrowser(browser);
            driver.Manage().Window.Maximize();
            driver.Wait(1);
            return(driver);
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            ChromeOptions options = new ChromeOptions();

            ChromeDriverService service = ChromeDriverService.CreateDefaultService();

            service.SuppressInitialDiagnosticInformation = true;

            IWebDriver driver = new ChromeDriver(service, options);

            options.AddArgument("--log-level=3");
            options.AddArgument("--silent");

            //Load main page
            driver.Url = "https://www.weightwatchers.com/us/";

            IWebElement FindWorkshop = driver.FindElement(By.XPath("(//a[@da-label='Find a Workshop'])[1]"));

            FindWorkshop.Click();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);

            IWebElement locationZip = driver.FindElement(By.XPath("//input[contains(@id,'location-search')]"));

            locationZip.SendKeys("10011");
            IWebElement locationsearch = driver.FindElement(By.XPath("(//button[contains(@id,'location-search-cta')])[1]"));

            locationsearch.Click();

            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            IWebElement FirstsearchResultTitle      = driver.FindElement(By.XPath("(//a[contains(@class,'linkUnderline-1_h4g')])[1]"));
            IWebElement FirstsearchResultDistance   = driver.FindElement(By.XPath("(//span[contains(@class,'distance-')])[1]"));

            String ResultTitle    = FirstsearchResultTitle.Text;
            String ResultDistance = FirstsearchResultDistance.Text;


            FirstsearchResultTitle.Click();
            driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
            IWebElement PageTitleElement            = driver.FindElement(By.XPath("//h1[contains(@class,'locationName')]"));
            IWebElement PageLocationElement         = driver.FindElement(By.XPath("(//div[contains(@class,'address-')])[1]//div"));

            if (ResultTitle != PageTitleElement.Text)
            {
                Console.Write("First search result not selected. Check here!");
                driver.Quit();
            }
            else
            {
                Console.WriteLine("\n");
                Console.WriteLine("First search Result Title    : " + ResultTitle);
                Console.WriteLine("First search Result Distance : " + ResultDistance + "\n");

                IList <IWebElement> AllMettingSchedules = driver.FindElements(By.XPath("//div[contains(@class,'meeting-')]"));
                for (int i = 1; i < AllMettingSchedules.Count; i++)
                {
                    Console.WriteLine(AllMettingSchedules[i].FindElement(By.XPath("./span[2]")).Text + "\t" + AllMettingSchedules[i].FindElement(By.XPath("./span[contains(@class,'meetingTime-')]")).Text);
                }
            }

            driver.Quit();
        }
 public ChromeDriverExtended(ChromeDriverService service) : base(service)
 {
     InitializeSendCommand();
 }
Beispiel #12
0
 public ChromeDriverEx(ChromeDriverService service, ChromeOptions options) : base(service, options, TimeSpan.FromMinutes(30))
 {
     ProcessId = service.ProcessId;
 }
Beispiel #13
0
        /*Acessa página dos arquivos de edital passando pelo captcha*/
        private static void DownloadEdAndCreatLicArq(string num, Licitacao licitacao)
        {
            RService.Log("(DownloadEdAndCreatLicArq) " + Name + ": Visualizando arquivos de edital, licitação... " + num + " at {0}", Path.GetTempPath() + Name + ".txt");

            try
            {
                if (web != null)
                {
                    web.Quit();
                }

                var driver = ChromeDriverService.CreateDefaultService();
                driver.HideCommandPromptWindow = true;
                var op = new ChromeOptions();
                op.AddUserProfilePreference("download.default_directory", PathEditais);
                web = new ChromeDriver(driver, new ChromeOptions(), TimeSpan.FromSeconds(300));
                web.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(300);
                wait = new WebDriverWait(web, TimeSpan.FromSeconds(300));


                web.Navigate().GoToUrl(licitacao.LinkEdital);

                if (TryReload)
                {
                    foreach (var a in web.FindElements(By.TagName("a")))
                    {
                        if (!string.IsNullOrEmpty(a.GetAttribute("onclick")) && a.GetAttribute("onclick").Contains("Listar documentos"))
                        {
                            web.ExecuteScript(a.GetAttribute("onclick"));
                            wait.Until(ExpectedConditions.ElementIsVisible(By.Id("idImgListarAnexo")));

                            web.ExecuteScript(GetScriptFillCaptcha("idImgListarAnexo", "inputCaptchaAnexosLicitacao"));
                            Thread.Sleep(1000);

                            web.ExecuteScript("document.getElementById('botao_continuar').click()");
                            Thread.Sleep(2000);

                            var select = web.FindElement(By.TagName("select"));
                            new SelectElement(select).SelectByValue("-1"); //mostrar todos

                            MatchCollection linkForm = Regex.Matches(web.PageSource, "numeroLicitacao=(.+?)&amp;sem-reg=true");

                            if (linkForm.Count > 0)
                            {
                                DownloadEditais(FindDocLinks(num), licitacao, linkForm);
                            }

                            if (Directory.Exists(PathEditais))
                            {
                                Directory.Delete(PathEditais, true);
                            }

                            break;
                        }
                    }
                }
                else
                {
                    web.ExecuteScript(GetScriptFillCaptcha("idImgListarAnexo", "inputCaptchaAnexosLicitacao"));
                    Thread.Sleep(1000);

                    web.ExecuteScript("document.getElementById('botao_continuar').click()");
                    Thread.Sleep(2000);

                    var select = web.FindElement(By.XPath("//*[@id=\"tDocumento_length\"]/label/select"));
                    new SelectElement(select).SelectByText("Todos");

                    MatchCollection linkForm = Regex.Matches(web.PageSource, "numeroLicitacao=(.+?)&amp;sem-reg=true");

                    DownloadEditais(FindDocLinks(num), licitacao, linkForm);

                    if (Directory.Exists(PathEditais))
                    {
                        Directory.Delete(PathEditais, true);
                    }
                }
            }
            catch (Exception e)
            {
                if (TryReload)
                {
                    RService.Log("Exception (DownloadEdAndCreatLicArq) " + Name + ": Falha na visualização, tentando novamente... " + num + " at {0}", Path.GetTempPath() + Name + ".txt");

                    TryReload = false;
                    DownloadEdAndCreatLicArq(num, licitacao);
                }
                else
                {
                    RService.Log("Exception (DownloadEdAndCreatLicArq) " + Name + ": " + e.Message + " / " + e.StackTrace + " / " + e.InnerException + " at {0}", Path.GetTempPath() + Name + ".txt");
                }

                TryReload = true;
            }
        }
        public void Run_Click(object sender, RoutedEventArgs e) //Run button!
        {
            Close();
            var driverService = ChromeDriverService.CreateDefaultService(@"\\brmserver\company\eComm\SellerASINScraper");

            driverService.HideCommandPromptWindow = true;
            var driver = new ChromeDriver(driverService, new ChromeOptions());

            string sellerID = SellerIDx.Text;

            driver.Url = "https://www.amazon.com/s?me=" + sellerID + "&rh=p_4%3ABob%27s+Red+Mill";


            Excel excel = new Excel();

            excel.CreateNewFile();
            //excel.CreateNewSheet();


            var cellCount       = 1;
            var pageItemCount   = 1;
            var pageNumber      = 2;
            int countPageNumber = 0;
            var checker         = "";
            var sellerName      = driver.FindElement(By.XPath("//*[@id='search']/span[2]/h1/div/div[1]/div/div/a/span")).Text;

            while (IsElementPresent(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[" + pageNumber + "]/a"), driver) == true) //the page numbers at the bottom
            {
                //pageItemCount = 1;

                while (IsElementPresent(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[4]/div[1]/div[" + pageItemCount + "]"), driver) == true) //the actual products
                {
                    string result = driver.FindElement(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[4]/div[1]/div[" + pageItemCount + "]")).GetAttribute("data-asin");
                    excel.WriteToCell(cellCount, 1, result);

                    cellCount++;
                    pageItemCount++; //maybe use this to tell program to stop. 16 Per full page. If less than 16 it doesn't need to run again. Downside is if the last page is 16 it won't shut off
                }
                pageItemCount = 1;
                pageNumber++;
                if (pageNumber > 6) //all elements are set to 6 after page 5, so this is necessary to keep the program running till the last page.
                {
                    pageNumber--;
                }



                if (IsElementPresent(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[" + pageNumber + "]/a"), driver) == true)
                {
                    checker = driver.FindElement(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[" + pageNumber + "]/a")).Text; //supposed to get the actual page number from within the element
                }

                int actualPageNumber = Convert.ToInt32(checker); //the only true count of what page you are on is collected by var checker.

                if (actualPageNumber == countPageNumber)         //Ends the program after it's reached the last page. The only way to know it's scraped all the asins is if it repeats itself
                {
                    pageNumber = 999;
                }
                else
                {
                    countPageNumber = actualPageNumber;
                }


                if (IsElementPresent(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[" + pageNumber + "]/a"), driver) == true) //clicks on the next page if it exists
                {
                    var clickPG = driver.FindElement(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[" + pageNumber + "]/a"));
                    clickPG.Click();
                }
            }

            //if (IsElementPresent(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[8]/div/span/div/div/ul/li[" + pageNumber + "]/a"), driver) == false) //for sellers with only one page of our products
            //{

            // while (IsElementPresent(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[4]/div[1]/div[" + pageItemCount + "]"), driver) == true)
            // {
            // string result = driver.FindElement(By.XPath("//*[@id='search']/div[1]/div[2]/div/span[3]/div[1]/div[" + pageItemCount + "]")).GetAttribute("data-asin");
            // excel.WriteToCell(cellCount, 1, result);

            // cellCount++;
            //pageItemCount++;
            //}

            //}

            excel.SaveAs(@"\\brmserver\company\eComm\SellerASINScraper\Reports\ASIN Report for " + sellerID + " - " + sellerName);
            excel.Quit();
            driver.Quit();
        }
Beispiel #15
0
 static DriverManager()
 {
     ChromeDriverService = ChromeDriverService.CreateDefaultService(@"../../../Resources");
 }
Beispiel #16
0
        public ChromeDriver()
        {
            var options = GetOptions();

            WebDriver = GetProtractorDriver(new OpenQA.Selenium.Chrome.ChromeDriver(ChromeDriverService.CreateDefaultService(), (ChromeOptions)options, TimeSpan.FromSeconds(90)));
        }
Beispiel #17
0
 public void Exit(IWebDriver driver, ChromeDriverService chromeDriverService)
 {
     driver.Quit();
     driver.Dispose();
     chromeDriverService.Dispose();
 }
Beispiel #18
0
        public static void Initialize(
            string driverType,
            bool isPrivateMode = true,
            bool isHeadless    = false)
        {
            switch (driverType)
            {
            case "IE":
                InternetExplorerDriverService service = InternetExplorerDriverService.CreateDefaultService();
                InternetExplorerOptions       options = new InternetExplorerOptions
                {
                    IgnoreZoomLevel = true
                };
                Instance = new InternetExplorerDriver(service, options);
                break;

            case "Chrome":
                //chrome
                ChromeDriverService svc           = ChromeDriverService.CreateDefaultService();
                ChromeOptions       chromeOptions = new ChromeOptions();
                if (isPrivateMode)
                {
                    chromeOptions.AddArgument("incognito");
                }

                if (isHeadless)
                {
                    chromeOptions.AddArgument("headless");
                }

                Instance = new ChromeDriver(svc, chromeOptions);
                break;

            case "Firefox":
                //firefox
                FirefoxDriverService geckoSvc = FirefoxDriverService.CreateDefaultService();
                var geckoOptions = new FirefoxOptions
                {
                    AcceptInsecureCertificates = true
                };

                if (isPrivateMode)
                {
                    geckoOptions.AddArgument("-private");
                }

                if (isHeadless)
                {
                    geckoOptions.AddArgument("-headless");
                }

                Instance = new FirefoxDriver(geckoSvc, geckoOptions);
                break;

            //case "Phantom":
            //    //Phantom Webdriver
            //    Instance = new PhantomJSDriver();
            //    break;

            default:
                Instance = new ChromeDriver();
                break;
            }

            Instance.Manage().Window.Maximize();
            Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
        }
        public void LoginWithSelenium(string userName, string password)
        {
            try
            {
                FbPageInfo fbPageInfo = new FbPageInfo();

                string       appStartupPath = System.IO.Path.GetDirectoryName(Assembly.GetCallingAssembly().Location);
                const string url            = "https://www.facebook.com/pages/?category=your_pages";
                _options.AddArgument("--disable-notifications");
                _options.AddArgument("--disable-extensions");
                _options.AddArgument("--test-type");
                _options.AddArgument("--log-level=3");
                ChromeDriverService chromeDriverService = ChromeDriverService.CreateDefaultService(appStartupPath);
                chromeDriverService.HideCommandPromptWindow = true;
                chromeWebDriver = new ChromeDriver(chromeDriverService, _options);
                chromeWebDriver.Manage().Window.Maximize();
                chromeWebDriver.Navigate().GoToUrl(url);
                try
                {
                    ((IJavaScriptExecutor)chromeWebDriver).ExecuteScript("window.onbeforeunload = function(e){};");
                }
                catch (Exception)
                {
                }

                ReadOnlyCollection <IWebElement> emailElement = chromeWebDriver.FindElements(By.Id("email"));
                if (emailElement.Count > 0)
                {
                    // emailElement[0].SendKeys("*****@*****.**");

                    emailElement[0].SendKeys(userName);

                    //CurrentLogedInFacebookUserinfo.Username = facebookUserinfo.Username
                }
                ReadOnlyCollection <IWebElement> passwordElement = chromeWebDriver.FindElements(By.Id("pass"));
                if (passwordElement.Count > 0)
                {
                    passwordElement[0].SendKeys(password);
                    // passwordElement[0].SendKeys(FileOperation.Password);
                }


                ReadOnlyCollection <IWebElement> signInElement = chromeWebDriver.FindElements(By.Id("loginbutton"));
                if (signInElement.Count > 0)
                {
                    signInElement[0].Click();
                    Thread.Sleep(3000);
                    //  chromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/pages/?category=your_pages");
                    // ChromeWebDriver.Navigate().GoToUrl(url);
                    // Thread.Sleep(2000);
                    //ChromeWebDriver.Navigate().GoToUrl("https://www.facebook.com/TP-1996120520653285/inbox/?selected_item_id=100002948674558");
                    try
                    {
                        var emailElement1 = chromeWebDriver.FindElements(By.XPath("//a[@class='_39g5']"));
                        foreach (var item in emailElement1)
                        {
                            string lin1k = item.GetAttribute("href");
                            if (item.GetAttribute("href").Contains("/live_video/launch_composer/?page_id="))
                            {
                                string pageId = lin1k.Replace("https://www.facebook.com/live_video/launch_composer/?page_id=", "");
                            }
                            if (item.GetAttribute("href").Contains("?modal=composer&ref=www_pages_browser_your_pages_section"))
                            {
                                string pageName = lin1k.Replace("https://www.facebook.com/", "").Replace("/?modal=composer&ref=www_pages_browser_your_pages_section", "");
                            }
                        }
                    }
                    catch (Exception)
                    {
                    }
                    finally
                    {
                        _cookieJar = chromeWebDriver.Manage().Cookies;

                        // chromeWebDriver.Quit();
                    }
                    //Thread.Sleep(5000);

                    LoginSuccessEvent();
                    // isLoggedIn = true;
                    //  Thread.Sleep(2000);
                }
            }
            catch (Exception)
            {
                //;
            }
        }
        public static void Main(string[] args)
        {
            context = new DatabaseContext();

            var options = new ChromeOptions();
            var chromeDriverService = ChromeDriverService.CreateDefaultService();
            chromeDriverService.HideCommandPromptWindow = true;
            options.AddArguments("--window-size=1920,1080", "--no-sandbox", "--headless");

            IWebDriver driver = new ChromeDriver(chromeDriverService, options);
            IWebDriver driverPigu = new ChromeDriver(chromeDriverService, options);

            driver.Navigate().GoToUrl("https://www.varle.lt/mobilieji-telefonai/");
            var products = driver.FindElements(By.CssSelector("div.grid-item.product"));

            foreach (var product in products)
            {
                string[] productInfo = product.Text.Split('\n');

                string absTitle = productInfo[0].Replace("(Atnaujinta)","").
                    Replace("(Pažeista pakuotė)","").
                    Replace("(Ekspozicinė prekė)", "");
                int index = absTitle.IndexOf("+DOVANA");
                if (index != -1) absTitle = absTitle.Substring(0, index);

                var dbProduct = new Product
                {
                    Title = absTitle,
                    Popularity = 0
                };
                var addedProduct = context.Products.Add(dbProduct);
                try
                {
                    context.SaveChanges();
                }
                catch (DbUpdateException) { }

                CreateAttribute(addedProduct.Entity, productInfo, "Gamintojas: ", "Manufacturer");
                CreateAttribute(addedProduct.Entity, productInfo, "Ekrano įstrižainė (coliais): ", "Size");
                CreateAttribute(addedProduct.Entity, productInfo, "Vidinė atmintis (GB): ", "Memory");
                CreateAttribute(addedProduct.Entity, productInfo, "Atmintis (RAM) (GB): ", "Ram");
                CreateAttribute(addedProduct.Entity, productInfo, "Ekrano raiška: ", "Resolution");

                var urlVarle = product.FindElement(By.CssSelector("a.title")).GetAttribute("href");
                var priceVarle = product.FindElement(By.CssSelector("span.price")).Text;
                priceVarle = priceVarle.Replace(",", CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator);
                priceVarle = priceVarle.Substring(0, priceVarle.Length - 2);
                var realProductVarle = new RealProduct
                {
                    AbstractProduct = addedProduct.Entity,
                    LastCheck = DateTime.Now,
                    Title = productInfo[0],
                    Price = decimal.Parse(priceVarle),
                    Url = urlVarle
                };
                context.RealProducts.Add(realProductVarle);
                addedProduct.Entity.RealProducts.Add(realProductVarle);

                driverPigu.Navigate().GoToUrl("https://pigu.lt/lt/search?q=" + absTitle);
                string urlPigu;
                try
                {
                    var productsPigu = driverPigu.FindElement(By.CssSelector("div.product-list.all-products-visible.clearfix.product-list--equal-height"));
                    string pricePigu = productsPigu.FindElement(By.CssSelector("span.price.notranslate")).Text.Substring(2);
                    pricePigu = pricePigu.Replace(",", CultureInfo.InvariantCulture.NumberFormat.NumberDecimalSeparator);
                    pricePigu = Regex.Replace(pricePigu, @"\s+", "");
                    string titlePigu = productsPigu.FindElement(By.CssSelector("p.product-name")).Text;
                    urlPigu = productsPigu.FindElement(By.CssSelector("a")).GetAttribute("href");
                    var realProducPigu = new RealProduct
                    {
                        AbstractProduct = addedProduct.Entity,
                        LastCheck = DateTime.Now,
                        Title = titlePigu,
                        Price = decimal.Parse(pricePigu),
                        Url = urlPigu
                    };
                    context.RealProducts.Add(realProducPigu);
                    addedProduct.Entity.RealProducts.Add(realProducPigu);
                }
                catch (NoSuchElementException) { }
                try
                {
                    context.SaveChanges();
                }
                catch (DbUpdateException) { }
            }

            driverPigu.Close();
            driverPigu.Quit();
            driver.Close();
            driver.Quit();
        }
Beispiel #21
0
        public static List <Shoes> Parse()
        {
            var service = ChromeDriverService.CreateDefaultService(Environment.CurrentDirectory);
            var options = new ChromeOptions();
            //options.AddArguments("--headless");


            List <string> sourceUrls      = new List <string>();
            List <Shoes>  resultListShoes = new List <Shoes>();
            bool          comPrmt         = false;

            using (IWebDriver driver = new ChromeDriver(service, options))
            {
                driver.Url =
                    @"https://www.walmart.com/browse/clothing/mens-shoes/5438_1045804_1045807?page=1&ps=48#searchProductResult";

                WebDriverWait waitForElement = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                waitForElement.Until(ExpectedConditions.ElementIsVisible(By.ClassName("GlobalFooterCopyright")));

                IWebElement elem = driver.FindElement(By.ClassName("GlobalFooterCopyright"));

                driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", elem);

                // get count of pages for parsing
                var pagesWebElements =
                    driver.FindElement(By.ClassName("paginator-list")).FindElements(By.TagName("li"));
                var lastPage = pagesWebElements[pagesWebElements.Count - 1].FindElement(By.TagName("a")).Text;


                // !!!!!!! ONLY FOR TEST
                //int lastPageNum = Int32.Parse(lastPage);
                int lastPageNum = 1;
                int currentPage = 0;



                // creating a list of urls
                string urlFirstPart = @"https://www.walmart.com/browse/clothing/mens-shoes/5438_1045804_1045807?page=";
                string urlEndPart   = @"&ps=48#searchProductResult";
                for (int pageIterator = 1; pageIterator <= lastPageNum; pageIterator++)
                {
                    string walmartUrl = urlFirstPart + pageIterator + urlEndPart;
                    sourceUrls.Add(walmartUrl);
                }

                foreach (var sourceUrl in sourceUrls)
                {
                    Stopwatch stopwatch = new Stopwatch();
                    stopwatch.Start();

                    currentPage = currentPage + 1;
                    driver.Url  = sourceUrl;

                    WebDriverWait waitForElement1 = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
                    waitForElement1.Until(ExpectedConditions.ElementIsVisible(By.ClassName("GlobalFooterCopyright")));
                    IWebElement elem1 = driver.FindElement(By.ClassName("GlobalFooterCopyright"));

                    driver.ExecuteJavaScript("arguments[0].scrollIntoView(true);", elem1);

                    var elements = driver.FindElement(By.ClassName("search-result-gridview-items"))
                                   .FindElements(By.ClassName("Grid-col"));



                    foreach (var webElement in elements)
                    {
                        Shoes shoes = new Shoes();
                        if (comPrmt)
                        {
                            Console.WriteLine(webElement.FindElement(By.TagName("img"))
                                              .GetAttribute("data-image-src"));
                        }

                        // img link
                        shoes.ShoesImageUrl = webElement.FindElement(By.TagName("img"))
                                              .GetAttribute("data-image-src");
                        try
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine(webElement.FindElement(By.ClassName("product-brand"))
                                                  .FindElement(By.TagName("strong")).Text);
                            }

                            // Brand name
                            shoes.ShoesBrand = webElement.FindElement(By.ClassName("product-brand"))
                                               .FindElement(By.TagName("strong")).Text;
                        }
                        catch (Exception e)
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine("No Brand Name");
                            }

                            shoes.ShoesBrand = "No Brand Name";
                        }

                        if (comPrmt)
                        {
                            Console.WriteLine(webElement.FindElement(By.TagName("img"))
                                              .GetAttribute("alt"));
                        }

                        // Shoes title
                        shoes.ShoesTitle = webElement.FindElement(By.TagName("img"))
                                           .GetAttribute("alt");

                        //try
                        //{
                        //    var selectors = webElement.FindElement(By.ClassName("swatch-selector"))
                        //        .FindElements(By.TagName("button"));
                        //    foreach (var selector in selectors)
                        //    {
                        //        if (comPrmt)
                        //        {
                        //            Console.WriteLine(selector.FindElement(By.TagName("img")).GetAttribute("alt"));
                        //        }

                        //        // shoes variants
                        //        string str = selector.FindElement(By.TagName("img")).GetAttribute("alt");
                        //        shoes.ShoesVariants.Add(str);
                        //    }
                        //}
                        //catch (Exception e)
                        //{
                        //    //Console.WriteLine(e.Message);

                        //    shoes.ShoesVariants.Add("No Variants");
                        //}

                        try
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine(webElement.FindElement(By.ClassName("price-group"))
                                                  .GetAttribute("aria-label"));
                            }

                            shoes.ShoesPrice = webElement.FindElement(By.ClassName("price-group"))
                                               .GetAttribute("aria-label");
                        }
                        catch (Exception e)
                        {
                            if (comPrmt)
                            {
                                Console.WriteLine("Out of Stock");
                            }

                            shoes.ShoesPrice = "Out of Stock";
                            //throw;
                        }

                        resultListShoes.Add(shoes);
                    }

                    stopwatch.Stop();
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine("Page {0} from {1} is parsed in {2:hh\\:mm\\:ss}", currentPage, lastPageNum,
                                      stopwatch.Elapsed);
                    Console.ResetColor();
                }

                return(resultListShoes);
            }
        }
Beispiel #22
0
        public void ReportCrawling()
        {
            _driverService = ChromeDriverService.CreateDefaultService();
            _driverService.HideCommandPromptWindow = true;
            _options = new ChromeOptions();
            _options.AddArgument("headless");
            _options.AddArgument("disable-gpu");
            _driver = new ChromeDriver(_driverService, _options);


            _driver.Navigate().GoToUrl("https://ieilms.jbnu.ac.kr/");             // 웹 사이트에 접속합니다.

            _driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);

            IWebElement element;

            try
            {
                element = _driver.FindElementByXPath("//*[@id='id']");
                element.SendKeys(VM.LoginModel.LoginID);

                element = _driver.FindElementByXPath("//*[@id='passwd']");
                element.SendKeys(VM.LoginModel.LoginPasswd);

                element = _driver.FindElementByXPath("//*[@id='loginform']/table/tbody/tr[1]/td[2]/input");
                element.Click();

                element = _driver.FindElementByXPath("//*[@id='boardAbox']/form/table/tbody/tr[1]/td[2]");
                element.Click();
            }
            catch (Exception)
            {
                MessageBox.Show("ID,PW를 확인해주세요.");
                return;
            }

            element = _driver.FindElementByXPath("//*[@id='nav']/li[4]/a");
            element.Click();

            if (grade == 21)
            {
                for (int i = 2; i < 10; i++)
                {
                    element = _driver.FindElementByXPath("//*[@id='center']/div/div[2]/div/div[3]/a/span");
                    element.Click();
                    string BASE_Path  = "//*[@id='treeboxtab']/div/table/tbody/tr[{0}]/td[2]/table/tbody/tr/td[4]/span";
                    string url        = string.Format(BASE_Path, i);
                    string BASE_value = url;
                    element = _driver.FindElementByXPath(BASE_value);
                    element.Click();
                    TextUpLoad3();
                }
            }
            if (grade == 18)
            {
                for (int i = 2; i < 9; i++)
                {
                    element = _driver.FindElementByXPath("//*[@id='center']/div/div[2]/div/div[3]/a/span");
                    element.Click();
                    string BASE_Path  = "//*[@id='treeboxtab']/div/table/tbody/tr[{0}]/td[2]/table/tbody/tr/td[4]/span";
                    string url        = string.Format(BASE_Path, i);
                    string BASE_value = url;
                    element = _driver.FindElementByXPath(BASE_value);
                    element.Click();
                    TextUpLoad3();
                }
            }
            if (grade == 15)
            {
                for (int i = 2; i < 8; i++)
                {
                    element = _driver.FindElementByXPath("//*[@id='center']/div/div[2]/div/div[3]/a/span");
                    element.Click();
                    string BASE_Path  = "//*[@id='treeboxtab']/div/table/tbody/tr[{0}]/td[2]/table/tbody/tr/td[4]/span";
                    string url        = string.Format(BASE_Path, i);
                    string BASE_value = url;
                    element = _driver.FindElementByXPath(BASE_value);
                    element.Click();
                    TextUpLoad3();
                }
            }
            _driver.Close();
        }
Beispiel #23
0
        /// <summary>
        /// Opens a browser of the given type (if not already open) and with the given settings.
        /// </summary>
        /// <param name="data">The BotData where the settings are stored.</param>
        public static void OpenBrowser(BotData data)
        {
            if (!data.BrowserOpen)
            {
                data.Log(new LogEntry("Opening browser...", Colors.White));

                switch (data.GlobalSettings.Selenium.Browser)
                {
                    case BrowserType.Chrome:
                        try
                        {
                            ChromeOptions chromeop = new ChromeOptions();
                            ChromeDriverService chromeservice = ChromeDriverService.CreateDefaultService();
                            chromeservice.SuppressInitialDiagnosticInformation = true;
                            chromeservice.HideCommandPromptWindow = true;   
                            chromeservice.EnableVerboseLogging = false;
                            chromeop.AddArgument("--log-level=3");
                            chromeop.BinaryLocation = data.GlobalSettings.Selenium.ChromeBinaryLocation;
                            if (data.GlobalSettings.Selenium.Headless || data.ConfigSettings.ForceHeadless) chromeop.AddArgument("--headless");
                            else if (data.GlobalSettings.Selenium.ChromeExtensions.Count > 0) // This should only be done when not headless
                                chromeop.AddExtensions(data.GlobalSettings.Selenium.ChromeExtensions
                                    .Where(ext => ext.EndsWith(".crx"))
                                    .Select(ext => Directory.GetCurrentDirectory() + "\\ChromeExtensions\\" + ext));
                            if (data.ConfigSettings.DisableNotifications) chromeop.AddArgument("--disable-notifications");
                            if (data.ConfigSettings.CustomCMDArgs != "") chromeop.AddArgument(data.ConfigSettings.CustomCMDArgs);
                            if (data.ConfigSettings.RandomUA) chromeop.AddArgument("--user-agent=" + BlockFunction.RandomUserAgent(data.rand));
                            else if (data.ConfigSettings.CustomUserAgent != "") chromeop.AddArgument("--user-agent=" + data.ConfigSettings.CustomUserAgent);

                            if (data.UseProxies) chromeop.AddArgument("--proxy-server=" + data.Proxy.Type.ToString().ToLower() + "://" + data.Proxy.Proxy);

                            data.Driver = new ChromeDriver(chromeservice, chromeop);
                        }
                        catch (Exception ex) { data.Log(new LogEntry(ex.ToString(), Colors.White)); return; }

                        break;

                    case BrowserType.Firefox:
                        try
                        {
                            FirefoxOptions fireop = new FirefoxOptions();
                            FirefoxDriverService fireservice = FirefoxDriverService.CreateDefaultService();
                            FirefoxProfile fireprofile = new FirefoxProfile();
                            
                            fireservice.SuppressInitialDiagnosticInformation = true;
                            fireservice.HideCommandPromptWindow = true;
                            fireop.AddArgument("--log-level=3");
                            fireop.BrowserExecutableLocation = data.GlobalSettings.Selenium.FirefoxBinaryLocation;
                            if (data.GlobalSettings.Selenium.Headless || data.ConfigSettings.ForceHeadless) fireop.AddArgument("--headless");
                            if (data.ConfigSettings.DisableNotifications) fireprofile.SetPreference("dom.webnotifications.enabled", false);
                            if (data.ConfigSettings.CustomCMDArgs != "") fireop.AddArgument(data.ConfigSettings.CustomCMDArgs);
                            if (data.ConfigSettings.RandomUA) fireprofile.SetPreference("general.useragent.override", BlockFunction.RandomUserAgent(data.rand));
                            else if (data.ConfigSettings.CustomUserAgent != "") fireprofile.SetPreference("general.useragent.override", data.ConfigSettings.CustomUserAgent);

                            if (data.UseProxies)
                            {
                                fireprofile.SetPreference("network.proxy.type", 1);
                                if (data.Proxy.Type == Extreme.Net.ProxyType.Http)
                                {
                                    fireprofile.SetPreference("network.proxy.http", data.Proxy.Host);
                                    fireprofile.SetPreference("network.proxy.httpport", int.Parse(data.Proxy.Port));
                                    fireprofile.SetPreference("network.proxy.ssl", data.Proxy.Host);
                                    fireprofile.SetPreference("network.proxy.sslport", int.Parse(data.Proxy.Port));
                                }
                                else
                                {
                                    fireprofile.SetPreference("network.proxy.socks", data.Proxy.Host);
                                    fireprofile.SetPreference("network.proxy.socksport", int.Parse(data.Proxy.Port));
                                    if (data.Proxy.Type == Extreme.Net.ProxyType.Socks4)
                                        fireprofile.SetPreference("network.proxy.socksversion", 4);
                                    else if (data.Proxy.Type == Extreme.Net.ProxyType.Socks5)
                                        fireprofile.SetPreference("network.proxy.socksversion", 5);
                                }
                            }

                            fireop.Profile = fireprofile;
                            data.Driver = new FirefoxDriver(fireservice, fireop, new TimeSpan(0, 1, 0));
                            
                        }
                        catch(Exception ex) { data.Log(new LogEntry(ex.ToString(), Colors.White)); return; }
                        
                        break;
                }

                data.Driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(data.GlobalSettings.Selenium.PageLoadTimeout);
                data.Log(new LogEntry("Opened!", Colors.White));
                data.BrowserOpen = true;
            }
            else
            {
                try
                {
                    UpdateSeleniumData(data);
                }
                catch { }
            }
        }
Beispiel #24
0
        private static Func <IWebDriver> GenerateBrowserSpecificDriver(Browser browser, TimeSpan commandTimeout)
        {
            string driverPath = string.Empty;

            switch (browser)
            {
            case Browser.InternetExplorer:
                driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer32.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver)));
                return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout)));

            case Browser.InternetExplorer64:
                driverPath = EmbeddedResources.UnpackFromAssembly("IEDriverServer64.exe", "IEDriverServer.exe", Assembly.GetAssembly(typeof(SeleniumWebDriver)));
                return(new Func <IWebDriver>(() => new Wrappers.IEDriverWrapper(Path.GetDirectoryName(driverPath), commandTimeout)));

            case Browser.Firefox:
                return(new Func <IWebDriver>(() => {
                    var firefoxBinary = new OpenQA.Selenium.Firefox.FirefoxBinary();
                    return new OpenQA.Selenium.Firefox.FirefoxDriver(firefoxBinary, new OpenQA.Selenium.Firefox.FirefoxProfile
                    {
                        EnableNativeEvents = false,
                        AcceptUntrustedCertificates = true,
                        AlwaysLoadNoFocusLibrary = true
                    }, commandTimeout);
                }));

            case Browser.Chrome:
                //Providing an unique name for the chromedriver makes it possible to run multiple instances
                var uniqueName       = string.Format("chromedriver_{0}.exe", Guid.NewGuid());
                var chromeDriverPath = ConfigReader.GetSetting("ChromeDriverPath");
                if (!string.IsNullOrEmpty(chromeDriverPath))
                {
                    driverPath = chromeDriverPath;
                    uniqueName = "chromedriver.exe";
                }
                else
                {
                    driverPath = EmbeddedResources.UnpackFromAssembly("chromedriver.exe", uniqueName,
                                                                      Assembly.GetAssembly(typeof(SeleniumWebDriver)));
                }

                var chromeService = ChromeDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath),
                                                                             uniqueName);

                chromeService.SuppressInitialDiagnosticInformation = true;
                var chromeOptions = new ChromeOptions();
                chromeOptions.AddArgument("--log-level=3");

                return(new Func <IWebDriver>(() => new OpenQA.Selenium.Chrome.ChromeDriver(chromeService, chromeOptions, commandTimeout)));

            case Browser.PhantomJs:
                var uniqueNamePhantom = string.Format("phantomjs_{0}.exe", Guid.NewGuid());
                driverPath = EmbeddedResources.UnpackFromAssembly("phantomjs.exe", uniqueNamePhantom, Assembly.GetAssembly(typeof(SeleniumWebDriver)));
                var phantomService = PhantomJSDriverService.CreateDefaultService(Path.GetDirectoryName(driverPath), uniqueNamePhantom);

                IWbTstr config    = WbTstr.Configure();
                string  proxyHost = config.GetPhantomProxyHost();
                if (!string.IsNullOrWhiteSpace(proxyHost))
                {
                    phantomService.Proxy     = proxyHost;
                    phantomService.ProxyType = "http";

                    string proxyAuthentication = config.GetPhantomProxyAuthentication();
                    if (!string.IsNullOrWhiteSpace(proxyAuthentication))
                    {
                        phantomService.ProxyAuthentication = proxyAuthentication;
                    }
                }

                return(new Func <IWebDriver>(() => new PhantomJSDriver(phantomService, new PhantomJSOptions(), commandTimeout)));
            }

            throw new NotImplementedException("Selected browser " + browser.ToString() + " is not supported yet.");
        }
        public String InitProcess(String contact, String file_route, String title, String chrome_binary)
        {
            try
            {
                if (!System.IO.File.Exists(file_route))
                {
                    return("Error : Attachment not found!");
                }
                if (!System.IO.File.Exists(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "chromedriver.exe")))
                {
                    return("Error : Chromedriver.exe executable not found!\n chromedriver.exe file is missing\n update or reinstalling may fix the problem");
                }
                var chrome_driver_service = ChromeDriverService.CreateDefaultService(AppDomain.CurrentDomain.BaseDirectory, "chromedriver.exe");
                chrome_driver_service.HideCommandPromptWindow = true;
                ChromeOptions chromeOptions = new ChromeOptions();
                chromeOptions.UnhandledPromptBehavior = UnhandledPromptBehavior.Accept;
                if (File.Exists(chrome_binary))
                {
                    chromeOptions.BinaryLocation = chrome_binary;
                }
                chrome_driver = new ChromeDriver(chrome_driver_service, chromeOptions);
                IJavaScriptExecutor javaScriptExecutor = (IJavaScriptExecutor)chrome_driver;
                foreach (string ct in contact.Split(','))
                {
                    if (string.IsNullOrEmpty(ct.Trim()))
                    {
                        break;
                    }
                    if (ct.Trim().Length != 12)
                    {
                        if (!(chrome_driver is null))
                        {
                            chrome_driver.Quit();
                        }
                        return("Error : Invalid contact number-" + ct);
                    }
                    chrome_driver.Url = "https://web.whatsapp.com/send?phone=" + ct.Trim();
                    try
                    {
                        chrome_driver.SwitchTo().Alert().Accept();
                    }
                    catch (NoAlertPresentException e1)
                    {
                        Console.WriteLine(e1.Message);
                    }

                    try
                    {
                        WebDriverWait wait = new WebDriverWait(chrome_driver, System.TimeSpan.FromSeconds(60));
                        wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='main']/footer/div[1]/div[2]/div/div[2]")));
                    }
                    catch (WebDriverTimeoutException)
                    {
                        continue;
                    }
                    //sending file
                    IWebElement file_open = chrome_driver.FindElement(By.XPath("//*[@id='main']/footer/div[1]/div[1]/div[2]/div/div/span"));
                    javaScriptExecutor.ExecuteScript("arguments[0].click();", file_open);
                    chrome_driver.FindElement(By.CssSelector("input[type='file']")).SendKeys(file_route);
                    WebDriverWait wait2 = new WebDriverWait(chrome_driver, System.TimeSpan.FromSeconds(30));
                    wait2.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementIsVisible(By.XPath("//*[@id='app']/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span")));
                    IWebElement file_send = chrome_driver.FindElement(By.XPath("//*[@id='app']/div/div/div[2]/div[2]/span/div/span/div/div/div[2]/span/div/div/span"));
                    javaScriptExecutor.ExecuteScript("arguments[0].click();", file_send);

                    Thread.Sleep(1000);

                    //sending text
                    IWebElement typebox = chrome_driver.FindElement(By.XPath("//*[@id='main']/footer/div[1]/div[2]/div/div[2]"));//:chrome_driver.FindElements(By.CssSelector("div[class ='_3u328 copyable-text selectable-text']"))[0];
                    typebox.SendKeys(title);
                    IWebElement text_send = chrome_driver.FindElement(By.XPath("//*[@id='main']/footer/div[1]/div[3]/button/span"));
                    javaScriptExecutor.ExecuteScript("arguments[0].click();", text_send);
                    Thread.Sleep(3000);
                }
                chrome_driver.Quit();
                return("Process finished");
            }
            catch (Exception ex)
            {
                if (!(chrome_driver is null))
                {
                    chrome_driver.Quit();
                }
                return(ex.Message);
            }
        }
Beispiel #26
0
        public static UserInfo Activate(Methods method, string igg_id, string promo)
        {
            ChromeDriverService service = ChromeDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;

            var options = new ChromeOptions();

            options.AddArgument("--window-position=-32000,-32000,performance");
            options.AddArgument("--headless");

            IWebDriver driver = new OpenQA.Selenium.Chrome.ChromeDriver(service, options);

            if (method == Methods.IGG_ID)
            {
                try
                {
                    driver.Manage().Window.Minimize();
                    driver.Navigate().GoToUrl("https://lordsmobile.igg.com/gifts/");

                    By igg_idInputElement = By.XPath("//input[@class='myname']");
                    By codeInputElement   = By.XPath("//input[@class='mycode']");
                    By claimButton        = By.Id("btn_claim_1");
                    By doneMessageElement = By.Id("msg");

                    var igg    = driver.FindElement(igg_idInputElement);
                    var code   = driver.FindElement(codeInputElement);
                    var submit = driver.FindElement(claimButton);

                    igg.Click();
                    igg.SendKeys(igg_id);
                    code.Click();
                    code.SendKeys(promo);
                    submit.Click();

                    var donemsg = driver.FindElement(doneMessageElement);
                    if (donemsg.Text != "Время действия кода истекло.[base]" && donemsg.Text != "Этот код уже был активирован!" && donemsg.Text != "Вы ввели неверный код.[C02]")
                    {
                        driver.Close();
                        driver.Quit();
                        return(new UserInfo()
                        {
                            Kingdom = 0, Power = "0", Result = Results.Sucess
                        });
                    }
                    else if (donemsg.Text == "Вы ввели неверный код.[C02]")
                    {
                        driver.Close();
                        driver.Quit();
                        return(new UserInfo()
                        {
                            Kingdom = 0, Power = "0", Result = Results.Invalid_Code
                        });
                    }
                    else if (donemsg.Text == "Время действия кода истекло.[base]")
                    {
                        driver.Close();
                        driver.Quit();
                        return(new UserInfo()
                        {
                            Kingdom = 0, Power = "0", Result = Results.Expired_Code
                        });
                    }
                    else if (donemsg.Text == "Этот код уже был активирован!")
                    {
                        driver.Close();
                        driver.Quit();
                        return(new UserInfo()
                        {
                            Kingdom = 0, Power = "0", Result = Results.Already_Activated
                        });
                    }
                    else
                    {
                        driver.Close();
                        driver.Quit();
                        return(new UserInfo()
                        {
                            Kingdom = 0, Power = "0", Result = Results.System_Error
                        });
                    }
                }
                catch
                {
                    return(new UserInfo()
                    {
                        Kingdom = 0, Power = "0", Result = Results.System_Error
                    });
                }
            }
            else if (method == Methods.Nickname)
            {
                try
                {
                    driver.Manage().Window.Minimize();
                    driver.Navigate().GoToUrl("https://lordsmobile.igg.com/gifts/");

                    var methodfind = driver.FindElement(By.ClassName("tab-list-2"));
                    methodfind.Click();
                    var nicknameInputfind = driver.FindElement(By.XPath("//input[@id='charname']"));
                    nicknameInputfind.Click();
                    nicknameInputfind.SendKeys(igg_id);
                    var code = driver.FindElement(By.XPath("//input[@id='cdkey_2']"));
                    code.Click();
                    code.SendKeys(promo);
                    var submit = driver.FindElement(By.Id("btn_claim_2"));
                    submit.Click();
                    var donemsg = driver.FindElement(By.Id("msg"));
                    if (donemsg.Text != "Игрок с таким именем не существует")
                    {
                        var    extramsg = driver.FindElement(By.Id("extra_msg"));
                        int    king     = int.Parse(Regex.Match(extramsg.Text, "Королевство: #(.*)").Groups[1].Value);
                        string pow      = (Regex.Match(extramsg.Text, "Сила: (.*)").Groups[1].Value);
                        var    submit2  = driver.FindElement(By.Id("btn_confirm"));
                        submit2.Click();

                        var donemsg2 = driver.FindElement(By.Id("msg"));
                        if (donemsg2.Text != "Время действия кода истекло.[base]" && donemsg2.Text != "Этот код уже был активирован!" && donemsg2.Text != "Вы ввели неверный код.[C02]")
                        {
                            driver.Close();
                            driver.Quit();
                            return(new UserInfo()
                            {
                                Kingdom = king, Power = pow, Result = Results.Sucess
                            });
                        }
                        else if (donemsg2.Text == "Вы ввели неверный код.[C02]")
                        {
                            driver.Close();
                            driver.Quit();
                            return(new UserInfo()
                            {
                                Kingdom = 0, Power = "0", Result = Results.Invalid_Code
                            });
                        }
                        else if (donemsg2.Text == "Время действия кода истекло.[base]")
                        {
                            driver.Close();
                            driver.Quit();
                            return(new UserInfo()
                            {
                                Kingdom = 0, Power = "0", Result = Results.Expired_Code
                            });
                        }
                        else if (donemsg2.Text == "Этот код уже был активирован!")
                        {
                            driver.Close();
                            driver.Quit();
                            return(new UserInfo()
                            {
                                Kingdom = king, Power = pow, Result = Results.Already_Activated
                            });
                        }
                        else
                        {
                            driver.Close();
                            driver.Quit();
                            return(new UserInfo()
                            {
                                Kingdom = 0, Power = "0", Result = Results.System_Error
                            });
                        }
                    }
                    else
                    {
                        driver.Close();
                        driver.Quit();
                        return(new UserInfo()
                        {
                            Kingdom = 0, Power = "0", Result = Results.Invalid_Nickname
                        });
                    }
                }
                catch
                {
                    driver.Close();
                    driver.Quit();
                    return(new UserInfo()
                    {
                        Kingdom = 0, Power = "0", Result = Results.System_Error
                    });
                }
            }
            else
            {
                driver.Close();
                driver.Quit();
                return(new UserInfo()
                {
                    Kingdom = 0, Power = "0", Result = Results.System_Error
                });
            }
        }
Beispiel #27
0
        public static IWebDriver Create(IConfiguration testConfig, out DriverService driverService)
        {
            var usingDriver = testConfig["usingDriver"];

            var driverHostName = default(string); // https://github.com/SeleniumHQ/selenium/issues/4988
            var driverOptions  = default(DriverOptions);
            var baseDir        = Environment.CurrentDirectory;

            switch (usingDriver)
            {
            case "Chrome":
                driverHostName = "127.0.0.1";
                driverService  = ChromeDriverService.CreateDefaultService(baseDir);
                driverOptions  = new ChromeOptions();
                break;

            case "Edge":
                driverHostName = "localhost";
                driverService  = EdgeDriverService.CreateDefaultService(baseDir);
                driverOptions  = new EdgeOptions();
                break;

            case "Firefox":
                driverHostName = "127.0.0.1";
                driverService  = FirefoxDriverService.CreateDefaultService(baseDir);
                driverOptions  = new FirefoxOptions();
                break;

            case "IE":
                driverHostName = "127.0.0.1";
                driverService  = InternetExplorerDriverService.CreateDefaultService(baseDir);
                driverOptions  = new InternetExplorerOptions();
                break;

            default:
                throw new Exception($"Unknown driver \"{usingDriver}\" was specified in configuration.");
            }

            try
            {
                driverService.HideCommandPromptWindow = true;
                driverService.Start();

                var webDriver = new RemoteWebDriver(new Uri($"http://{driverHostName}:{driverService.Port}"), driverOptions);
                try
                {
                    //webDriver.Manage().Window.Maximize();
                    //webDriver.Manage().Window.Position = new Point(x: 426, y: 0);
                    //webDriver.Manage().Window.Size = new Size(width: 854, height: 720);

                    webDriver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(5);
                    webDriver.Manage().Timeouts().PageLoad     = TimeSpan.FromSeconds(5);
                    return(webDriver);
                }
                catch
                {
                    webDriver.Dispose();
                    throw;
                }
            }
            catch
            {
                driverService.Dispose();
                driverService = null;
                throw;
            }
        }
Beispiel #28
0
        public static List <FollowUp> GetFollowUps(string username, string password)
        {
            List <FollowUp> result   = new List <FollowUp>();
            var             loginUrl = "https://www.followupthen.com/login";

            ChromeOptions options = new ChromeOptions();

            options.AddArgument("--headless");

            ChromeDriverService service = ChromeDriverService.CreateDefaultService();

            service.HideCommandPromptWindow = true;

            try
            {
                using (var driver = new ChromeDriver(service, options))
                {
                    driver.Navigate().GoToUrl(loginUrl);
                    var usernameField = driver.FindElementByName("email");
                    var passwordField = driver.FindElementByName("password");
                    var loginButton   = driver.FindElementByXPath("//*[@type='submit']");

                    usernameField.SendKeys(username);
                    passwordField.SendKeys(password);
                    loginButton.Click();

                    //Scroll the page to dynamically load all the followups
                    var followUps = driver.FindElementsByXPath("//*[@class='row_container ng-scope']").ToList();
                    while (followUps.Count == 0)
                    {
                        followUps = driver.FindElementsByXPath("//*[@class='row_container ng-scope']").ToList();
                    }

                    var footer        = driver.FindElementByTagName("footer");
                    int followUpCount = 0;
                    while (followUpCount != followUps.Count)
                    {
                        followUpCount = followUps.Count;
                        Actions actions = new Actions(driver);
                        actions.MoveToElement(footer);
                        actions.Perform();
                        System.Threading.Thread.Sleep(500); //Wait for page to load the new followups
                        followUps = driver.FindElementsByXPath("//*[@class='row_container ng-scope']").ToList();
                    }

                    //Get the followups
                    foreach (var followUp in followUps)
                    {
                        FollowUp newFollowUp = new FollowUp();

                        var titleElement = followUp.FindElement(By.XPath(".//*[@class='subject ng-binding']"));
                        newFollowUp.Title = titleElement.Text;

                        var      timeElement = followUp.FindElement(By.XPath(".//*[@class='fut_time ng-scope ng-binding']"));
                        DateTime followUpTime;
                        DateTime.TryParseExact(timeElement.Text, "H:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out followUpTime);
                        if (followUpTime == DateTime.MinValue)
                        {
                            DateTime.TryParseExact(timeElement.Text, "ddd, MMM d H:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out followUpTime);
                        }

                        if (followUpTime == DateTime.MinValue)
                        {
                            DateTime.TryParseExact(timeElement.Text, "ddd, MMM d, yyyy H:mm", CultureInfo.InvariantCulture, DateTimeStyles.AssumeLocal, out followUpTime);
                        }

                        newFollowUp.Time = followUpTime;

                        //newFollowUp.Url //Because of the way followupthen.com works, this is currently not supported
                        result.Add(newFollowUp);
                    }
                }
            }
            catch
            {
            }

            return(result);
        }
Beispiel #29
0
        public bool FuncionPrincipal(string usuario, string contraseña, DateTime FI, DateTime FF)
        {
            bool exito = true;

            string[] rutaArchivoRetenidos = new string[0];
            string[] rutaArchivoSaldo     = new string[0];
            string[] rutaArchivoHistorico = new string[0];
            DateTime Inicio = DateTime.Now;

            if (FI > FF.AddDays(-90))
            {
                ChromeDriverService driverService = ChromeDriverService.CreateDefaultService();
                driverService.HideCommandPromptWindow = true;
                driver = new ChromeDriver(driverService, new ChromeOptions());
                driver.Navigate().GoToUrl("https://portal-financiero.chedraui.com.mx/#/account/login");
                bool bandera = false;
                do
                {
                    try
                    {
                        driver.FindElement(By.Name("username"));
                        bandera = false;
                    }
                    catch
                    {
                        bandera = true;
                        Thread.Sleep(500);
                    }
                } while (bandera != false);
                bandera = false;
                driver.FindElement(By.Name("username")).Clear();
                driver.FindElement(By.Name("username")).SendKeys(usuario);
                driver.FindElement(By.Name("password")).Clear();
                driver.FindElement(By.Name("password")).SendKeys(contraseña);
                Thread.Sleep(1000);
                ReadOnlyCollection <IWebElement> buttons = driver.FindElements(By.TagName("button"));
                for (int a = 0; a < buttons.Count; a++)
                {
                    string texto = buttons[a].Text;
                    if (texto == "INICIAR SESIÓN")
                    {
                        buttons[a].Click();
                        a = buttons.Count;
                    }
                }
                do
                {
                    try
                    {
                        driver.FindElement(By.Id("side-menu"));
                        bandera = false;
                        Thread.Sleep(3000);
                    }
                    catch
                    {
                        bandera = true;
                        Thread.Sleep(500);
                    }
                } while (bandera != false);
                IWebElement menu = driver.FindElement(By.Id("side-menu"));
                ReadOnlyCollection <IWebElement> menus = menu.FindElements(By.TagName("li"));
                int numeroMenu = 0;
                Thread.Sleep(3000);
                for (int a = 0; a < menus.Count; a++)
                {
                    string texto = menus[a].Text;
                    if (texto == "Estado de Cuenta")
                    {
                        menus[a].Click();
                        numeroMenu = a;
                        a          = menus.Count;
                    }
                }
                Thread.Sleep(1000);
                ReadOnlyCollection <IWebElement> submenus = menus[numeroMenu].FindElements(By.TagName("li"));
                for (int a = 0; a < submenus.Count; a++)
                {
                    string texto = submenus[a].Text;
                    if (texto == "Saldo en Cuenta")
                    {
                        submenus[a].Click();
                        a = submenus.Count;
                    }
                }

                do
                {
                    try
                    {
                        IWebElement alerta    = driver.FindElement(By.Id("WaitProgress"));
                        string      propiedad = alerta.GetAttribute("style");
                        if (propiedad == "display: none;")
                        {
                            bandera = true;
                        }
                        else
                        {
                            bandera = false;
                            Thread.Sleep(500);
                        }
                    }
                    catch
                    {
                    }
                } while (bandera != false);

                rutaArchivoSaldo = descargarSaldo(FI, FF);
                Thread.Sleep(2000);
                for (int a = 0; a < submenus.Count; a++)
                {
                    string texto = submenus[a].Text;
                    if (texto == "Documentos Retenidos")
                    {
                        submenus[a].Click();
                        a = submenus.Count;
                    }
                }

                do
                {
                    try
                    {
                        IWebElement alerta    = driver.FindElement(By.Id("WaitProgress"));
                        string      propiedad = alerta.GetAttribute("style");
                        if (propiedad == "display: none;")
                        {
                            bandera = true;
                        }
                        else
                        {
                            bandera = false;
                            Thread.Sleep(500);
                        }
                    }
                    catch
                    {
                    }
                } while (bandera != false);

                rutaArchivoRetenidos = descargarSaldo(FI, FF);
                Thread.Sleep(2000);
                for (int a = 0; a < submenus.Count; a++)
                {
                    string texto = submenus[a].Text;
                    if (texto == "Movimientos Históricos")
                    {
                        submenus[a].Click();
                        a = submenus.Count;
                    }
                }

                do
                {
                    try
                    {
                        IWebElement alerta    = driver.FindElement(By.Id("WaitProgress"));
                        string      propiedad = alerta.GetAttribute("style");
                        if (propiedad == "display: none;")
                        {
                            bandera = true;
                        }
                        else
                        {
                            bandera = false;
                            Thread.Sleep(500);
                        }
                    }
                    catch
                    {
                    }
                } while (bandera != false);

                rutaArchivoHistorico = descargarSaldo(FI, FF);
                for (int a = 0; a < menus.Count; a++)
                {
                    string texto = menus[a].Text;
                    if (texto == "Salir")
                    {
                        menus[a].Click();
                        a = menus.Count;
                    }
                }
                Thread.Sleep(1000);
                buttons = driver.FindElements(By.TagName("button"));
                foreach (IWebElement item in buttons)
                {
                    string texto = item.Text;
                    if (texto == "ACEPTAR")
                    {
                        item.Click();
                        break;
                    }
                }
                bandera = false;
                do
                {
                    try
                    {
                        driver.FindElement(By.Name("username"));
                        bandera = false;
                    }
                    catch
                    {
                        bandera = true;
                        Thread.Sleep(500);
                    }
                } while (bandera != false);
                try
                {
                    driver.Close();
                    driver.Quit();
                }
                catch { }
                if (rutaArchivoSaldo.Length > 0 && rutaArchivoRetenidos.Length > 0 & rutaArchivoHistorico.Length > 0)
                {
                    consolidarArchivos(rutaArchivoSaldo[0], rutaArchivoRetenidos[0], rutaArchivoHistorico[0]);
                }
                else if (rutaArchivoSaldo.Length > 0 && rutaArchivoRetenidos.Length > 0 & rutaArchivoHistorico.Length == 0)
                {
                    consolidarArchivos(rutaArchivoSaldo[0], rutaArchivoRetenidos[0], "Saldo en Cuenta", "Documentos Retenidos");
                }
                else if (rutaArchivoSaldo.Length > 0 && rutaArchivoRetenidos.Length == 0 & rutaArchivoHistorico.Length > 0)
                {
                    consolidarArchivos(rutaArchivoSaldo[0], rutaArchivoHistorico[0], "Saldo en Cuenta", "Movimientos Historicos");
                }
                else if (rutaArchivoSaldo.Length > 0 && rutaArchivoRetenidos.Length == 0 & rutaArchivoHistorico.Length == 0)
                {
                    string            rut     = moverArchivo(rutaArchivoSaldo[0], "Saldo en cuenta");
                    Excel.Application miExcel = new Excel.Application();
                    miExcel.Visible       = true;
                    miExcel.DisplayAlerts = false;
                    Excel.Workbook libro = miExcel.Workbooks.Open(rut);
                    ((Excel.Worksheet)miExcel.Sheets[1]).Select();
                    Excel.Worksheet SheetExcel = (Excel.Worksheet)libro.ActiveSheet;
                    SheetExcel.Columns.EntireColumn.AutoFit();
                    Excel.Range rango = SheetExcel.get_Range("1:1");
                    rango.Select();
                    rango.Interior.ThemeColor = Excel.XlThemeColor.xlThemeColorAccent2;
                    rango.Font.ThemeColor     = Excel.XlThemeColor.xlThemeColorDark1;
                    rango.Font.Bold           = true;
                    SheetExcel.Name           = "Saldo en Cuenta";
                    libro.Save();
                }
                else if (rutaArchivoSaldo.Length == 0 && rutaArchivoRetenidos.Length == 0 & rutaArchivoHistorico.Length > 0)
                {
                    string            rut     = moverArchivo(rutaArchivoHistorico[0], "Movientos Historicos");
                    Excel.Application miExcel = new Excel.Application();
                    miExcel.Visible       = true;
                    miExcel.DisplayAlerts = false;
                    Excel.Workbook libro = miExcel.Workbooks.Open(rut);
                    ((Excel.Worksheet)miExcel.Sheets[1]).Select();
                    Excel.Worksheet SheetExcel = (Excel.Worksheet)libro.ActiveSheet;
                    SheetExcel.Columns.EntireColumn.AutoFit();;
                    Excel.Range rango = SheetExcel.get_Range("1:1");
                    rango.Select();
                    rango.Interior.ThemeColor = Excel.XlThemeColor.xlThemeColorAccent2;
                    rango.Font.ThemeColor     = Excel.XlThemeColor.xlThemeColorDark1;
                    rango.Font.Bold           = true;
                    SheetExcel.Name           = "Movimientos Historicos";
                    libro.Save();
                }
                else if (rutaArchivoSaldo.Length == 0 && rutaArchivoRetenidos.Length > 0 & rutaArchivoHistorico.Length == 0)
                {
                    string            rut     = moverArchivo(rutaArchivoRetenidos[0], "Documentos Retenidos");
                    Excel.Application miExcel = new Excel.Application();
                    miExcel.Visible       = true;
                    miExcel.DisplayAlerts = false;
                    Excel.Workbook libro = miExcel.Workbooks.Open(rut);
                    ((Excel.Worksheet)miExcel.Sheets[1]).Select();
                    Excel.Worksheet SheetExcel = (Excel.Worksheet)libro.ActiveSheet;
                    SheetExcel.Columns.EntireColumn.AutoFit();
                    Excel.Range rango = SheetExcel.get_Range("1:1");
                    rango.Select();
                    rango.Interior.ThemeColor = Excel.XlThemeColor.xlThemeColorAccent2;
                    rango.Font.ThemeColor     = Excel.XlThemeColor.xlThemeColorDark1;
                    rango.Font.Bold           = true;
                    SheetExcel.Name           = "Documentos Retenidos";
                    libro.Save();
                }
                else if (rutaArchivoSaldo.Length == 0 && rutaArchivoRetenidos.Length > 0 & rutaArchivoHistorico.Length > 0)
                {
                    consolidarArchivos(rutaArchivoRetenidos[0], rutaArchivoHistorico[0], "Documentos Retenidos", "Movimientos Historicos");
                }
                else if (rutaArchivoSaldo.Length == 0 && rutaArchivoRetenidos.Length == 0 & rutaArchivoHistorico.Length == 0)
                {
                }
            }
            else
            {
                MessageBox.Show("La consulta no puede ser mayor a 90 dias");
            }
            return(exito);
        }
Beispiel #30
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Browser = new OpenQA.Selenium.Chrome.ChromeDriver();
            var optn    = new ChromeOptions();
            var service = ChromeDriverService.CreateDefaultService();

            service.LogPath = "chromedriver.log";
            service.EnableVerboseLogging = true;
            Browser = new ChromeDriver(service, optn);
            try
            {
                Browser.Navigate().GoToUrl("http://prestashop-automation.qatestlab.com.ua/ru/");
                richTextBox1.Text += ("Connecting to http://prestashop-automation.qatestlab.com.ua/ru/ ... \n");
            }
            catch (Exception)
            {
                richTextBox1.Text += ("URL http://prestashop-automation.qatestlab.com.ua/ru/ doesn't respond!\n");
                Browser.Close();
            }
            IWebElement        Currency_selector = Browser.FindElement(By.Id("_desktop_currency_selector"));
            List <IWebElement> CurrencyA         = Currency_selector.FindElements(By.TagName("span")).ToList();
            IWebElement        CurrencyField     = Currency_selector.FindElement(By.TagName("ul"));
            List <IWebElement> CurrencyList      = CurrencyField.FindElements(By.TagName("li")).ToList();
            IWebElement        ProductsField     = Browser.FindElement(By.ClassName("products"));
            List <IWebElement> Product           = ProductsField.FindElements(By.TagName("article")).ToList();

            for (int i = 0; i < CurrencyList.Count; i++)
            {
                CurrencyA[1].Click();
                Thread.Sleep(1000);
                CurrencyList[i].Click();
                Currency_selector = Browser.FindElement(By.Id("_desktop_currency_selector"));
                CurrencyA         = Currency_selector.FindElements(By.TagName("span")).ToList();
                CurrencyField     = Currency_selector.FindElement(By.TagName("ul"));
                CurrencyList      = CurrencyField.FindElements(By.TagName("li")).ToList();
                ProductsField     = Browser.FindElement(By.ClassName("products"));
                Product           = ProductsField.FindElements(By.TagName("article")).ToList();
                if (i == 1)
                {
                    ChechPriceUAH(Product);
                }
                if (i == 0)
                {
                    ChechPriceEUR(Product);
                }
                if (i == 2)
                {
                    ChechPriceUSD(Product);
                }
            }
            richTextBox1.Text += ("Switch to USD price...\n");
            CurrencyA[1].Click();
            Thread.Sleep(1000);
            CurrencyList[2].Click();
            IWebElement SearchField  = Browser.FindElement(By.Id("search_widget"));
            IWebElement SearchText   = SearchField.FindElement(By.Name("s"));
            IWebElement SearchButton = SearchField.FindElement(By.TagName("button"));

            SearchText.Click();
            SearchText.SendKeys("dress");
            Thread.Sleep(500);
            richTextBox1.Text += "Search for key (dress)\n";
            SearchButton.Click();
            Thread.Sleep(500);
            richTextBox1.Text += "Check products for key (dress)\n";
            ProductsField      = Browser.FindElement(By.Id("products"));
            Product            = ProductsField.FindElements(By.TagName("article")).ToList();
            int B = 0;

            B = ChechRealAnsw(Product);
            IWebElement Count = ProductsField.FindElement(By.TagName("p"));

            string[] buf  = Count.Text.Split(new char[] { ' ' });
            char[]   buf2 = buf[1].ToArray();
            if (Convert.ToInt32(buf2[0].ToString()) == B)
            {
                richTextBox1.Text += ("Find elements:" + Product.Count.ToString() + " is correct!\n");
            }
            else
            {
                richTextBox1.Text += ("Find elements:" + B.ToString() + " not correct!\n");
            }
            ChechPriceUSD(Product);
            Count = ProductsField.FindElement(By.ClassName("select-title"));
            Count.Click();
            Count = ProductsField.FindElement(By.ClassName("dropdown-menu"));
            List <IWebElement> DropDownMenu = Count.FindElements(By.TagName("a")).ToList();

            DropDownMenu[4].Click();
            Thread.Sleep(1000);
            ProductsField      = Browser.FindElement(By.Id("products"));
            Product            = ProductsField.FindElements(By.TagName("article")).ToList();
            richTextBox1.Text += ("Chech sorting...\n");
            if (CheckSort(Product) == true)
            {
                richTextBox1.Text += ("Sorting is correct!\n");
            }
            else
            {
                richTextBox1.Text += ("Sorting is not correct!\n");
            }
            richTextBox1.Text += ("Chech discount...\n");
            if (CheckSale(Product) == true)
            {
                richTextBox1.Text += ("Discount is correct!\n");
            }
            else
            {
                richTextBox1.Text += ("Discount is not correct!\n");
            }
            richTextBox1.Text += ("End of test!");
            Browser.Close();
        }