//Region "//*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[1]/div/div[1]/span[1]/span"
        //    //*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div/div[2]/div/div[2]/div[1]/div/ul/li[29]/label

        //    Volume (Intraday) "//*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[2]/div/div[1]/span[1]/span"
        //    //*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[2]/div/div/div[2]/div[1]/div/ul/li[6]/label
        //      *[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[3]/div/div/div[2]/div[1]/div/ul/li[6]/label

        //    Percent Change "//*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[3]/div/div[1]/span[1]/span"
        //    //*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[2]/div/div/div[2]/div[1]/div/ul/li[28]/label

        //    Market Cap (Intraday)
        //    //*[@id="screener-criteria"]/div[2]/div[1]/div[1]/div[2]/div/div/div[2]/div[3]/div/ul/li[6]/label



        public IEnumerable <StockActiveDto> GetStockskActive(StockActiveQueryParameters stockActiveQueryParameters)
        {
            _stockActiveQueryParameters = stockActiveQueryParameters;
            IEnumerable <StockActiveDto> allStocksActive = ScrapStocksActive(_stockActiveQueryParameters);

            if (allStocksActive == null)
            {
                return(null);
            }
            return(allStocksActive);
        }
 private void SetFilters(IWebDriver driver, StockActiveQueryParameters stockActiveQueryParameters)
 {
     if (_filtersFailed > _maxFilterFailed)
     {
         throw new ArgumentException("Error - {this.GetType()} failed to set up filters {_maxFilterFailed.ToString()} timea.");
     }
     ClearFilters(driver);
     SetFilterRegion(driver, _stockActiveQueryParameters.Countries);
     SetFilterMarketCap(driver, _stockActiveQueryParameters.MarketCapIntraday);
     SetFilterVolumeIntraday(driver, _stockActiveQueryParameters.VolumeIntradayCondition, _stockActiveQueryParameters.VolumeIntraday, _stockActiveQueryParameters.VolumeIntraday2);
 }
        public IEnumerable <StockActiveDto> ScrapStocksActive(StockActiveQueryParameters stockActiveQueryParameters)
        {
            var options = new ChromeOptions();

            // set some options
            options.ToCapabilities();
            //IWebDriver driver = new RemoteWebDriver(new Uri(""), options); for remote in a Docker container
            //Local Chrome driver for debug mode
            IWebDriver driver = new ChromeDriver(Environment.CurrentDirectory + "\\ThirdPart\\Selenium\\ChromeDriver", options);

            try
            {
                _stockActiveList = new List <StockActiveDto>();
                Uri uri                  = SetUri();
                int pageCount            = 100;
                int pageOffset           = 0;
                HtmlNodeCollection nodes = new HtmlNodeCollection(null);
                driver.Url = uri.ToString() + $"?offset={pageOffset}&count={pageCount}";
                SetFilters(driver, _stockActiveQueryParameters);



                bool nextPageRecordsExists = false;
                do
                {
                    if (nextPageRecordsExists)
                    {
                        driver.FindElement(By.XPath("//*[@id=\"fin-scr-res-table\"]/div[2]/div[2]/button[3]")).Click();
                    }
                    HtmlDocument doc = new HtmlDocument();
                    doc.LoadHtml(driver.PageSource);
                    var _nodes = doc.DocumentNode.SelectNodes("//*[@id=\"scr-res-table\"]/table/tbody/tr");
                    if (_nodes == null)
                    {
                        break;
                    }
                    foreach (var node in _nodes)
                    {
                        nodes.Add(node);
                    }
                    if (driver.FindElementSafe(By.XPath("//*[@id=\"fin-scr-res-table\"]/div[2]/div[2]/button[3]")) != null && driver.FindElement(By.XPath("//*[@id=\"fin-scr-res-table\"]/div[2]/div[2]/button[3]")).Displayed&& driver.FindElement(By.XPath("//*[@id=\"fin-scr-res-table\"]/div[2]/div[2]/button[3]")).Enabled)
                    {
                        nextPageRecordsExists = true;
                    }
                    else
                    {
                        driver.Quit();
                        nextPageRecordsExists = false;
                    }
                } while (nextPageRecordsExists);

                if (nodes == null)
                {
                    return(_stockActiveList);
                }
                StockActiveDto stockActiveDto;
                foreach (var node in nodes)
                {
                    var    nodeUriPath = node.ChildNodes.ElementAt(1).FirstChild.GetAttributeValue("href", "");
                    string nodeUri     = "";
                    if (nodeUriPath != "")
                    {
                        nodeUri = _uriHost + nodeUriPath;
                    }
                    stockActiveDto = new StockActiveDto
                    {
                        Symbol           = node.ChildNodes.ElementAt(1).FirstChild.InnerText,
                        Url              = nodeUri,
                        Name             = node.ChildNodes.ElementAt(2).InnerText,
                        Price            = StrToDecParse(node.ChildNodes.ElementAt(3).FirstChild.InnerText),
                        Change           = StrToDecParse(node.ChildNodes.ElementAt(4).FirstChild.InnerText),
                        ChangePercentage = StrToDecParse(node.ChildNodes.ElementAt(5).FirstChild.InnerText.Replace("%", string.Empty)),
                        Volume           = StrToDecParse(node.ChildNodes.ElementAt(6).InnerText),
                        AvgVol3Mth       = StrToDecParse(node.ChildNodes.ElementAt(7).InnerText),
                        MarketCap        = StrToDecParse(node.ChildNodes.ElementAt(8).InnerText),
                        PERatioTTM       = StrToDecParse((node.ChildNodes.ElementAt(9).FirstChild.InnerText ?? node.ChildNodes.ElementAt(9).InnerText)),
                        //Week52Range = node.ChildNodes.ElementAt(10).InnerText - there is a picture loaded by JS.
                        Week52Range = string.Empty
                    };

                    _stockActiveList.Add(stockActiveDto);
                }
            }
            catch (Exception e)
            {
                _logger.Error(e, "Error");
                _stockActiveList = null;
                driver.Quit();
            }
            return(_stockActiveList);
        }