Exemplo n.º 1
0
        private void FindFlights(string departureCity, string destinationCountry, string destinationCity)
        {
            //set destination City
            DestinationCityElm.SelectByText(destinationCity);
            if (!DatesSet)
            {
                SetDates();
            }

            try
            {
                Screenshot screen = ((ITakesScreenshot)_driver).GetScreenshot();
                screen.SaveAsFile($"PegasBeforeSearch{DateTime.Now.ToString("yyyy.MM.dd.HH.m")}.png", ScreenshotImageFormat.Png);

                SearchButtonElm.Click();
                Thread.Sleep(5000);
            }
            catch (ElementClickInterceptedException ex)
            {
                _logger?.LogError(ex, $"departureCity {departureCity} destination {destinationCity}");
                ReloadAndRestorePage(departureCity, destinationCountry, destinationCity);
            }
            Thread.Sleep(5000);

            var flightTables = _driver.FindElements(By.XPath(OneWayFlightsPath));

            if (flightTables.Any())
            {
                var departureCityCode   = IataCities.FirstOrDefault(icity => icity.Name == departureCity)?.Code;
                var destinationCityCode = IataCities.FirstOrDefault(icity => icity.Name == destinationCity)?.Code;
                if (departureCityCode == null)
                {
                    Debug.WriteLine(departureCityCode);
                }
                if (destinationCityCode == null)
                {
                    Debug.WriteLine(destinationCityCode);
                }
                FlightsList.AddRange(ParseFlights(departureCity, departureCityCode, destinationCountry, destinationCity, flightTables.First()));
            }
            else
            {
                _logger?.LogWarning($"[Pegas] Город вылета {departureCity}. " +
                                    $"Страна прилёта {destinationCountry}. Город прилёта {destinationCity}. " +
                                    $"Нет рейсов");
            }
        }
Exemplo n.º 2
0
        private void FindFlights(string airCompany, string departureCity, string destinationCity)
        {
            //new Actions(_driver).MoveToElement(SearchButtonElm).MoveByOffset(0, 30).Click().Perform();
            AirCompanyDropDownElm.Click();

            var by = string.Format(SearchPattern, airCompany);

            Thread.Sleep(2200);
            AirCompanyElm.FindElement(By.XPath(by)).Click();
            Thread.Sleep(2200);

            SearchButtonElm.Click();
            Thread.Sleep(25500);

            var flights = _driver.FindElements(By.XPath(ResultsTablePath));

            if (flights.Any())
            {
                InitControls();
                FlightsList.AddRange(ParseFlights(departureCity, destinationCity, airCompany, flights.First()));
            }
        }