private static async Task <string> GetSingleClassWithPrefix(IBrowser browser, string targetNodeType, string classPrefix) { var classesWithPrefix = await GetClassesWithPrefixNameScript()(browser, targetNodeType, classPrefix).ConfigureAwait(false); if (classesWithPrefix.Length != 1) { throw new Exception($"Expected exactly one class with the prefix '{classPrefix}', but found {classesWithPrefix.Length}!"); } return(classesWithPrefix[0]); }
private static async Task <string> GetSingleClassWithFirstPrefix(IBrowser browser, string targetNodeType, params string[] classPrefixes) { foreach (var classPrefix in classPrefixes) { var classesWithPrefix = await GetClassesWithPrefixNameScript()(browser, targetNodeType, classPrefix).ConfigureAwait(false); if (classesWithPrefix.Length == 1) { return(classesWithPrefix.Single()); } } throw new Exception("Could not find any suitable class!"); }
private static async Task SelectDate(IBrowser browser, DateTimeOffset date) { var maxMonthsInFuture = 12; var monthsToMove = MonthsBetween(DateTimeOffset.Now, date); if (monthsToMove < 0) { throw new ArgumentException($"Cannot select a date in the past ({date})!"); } if (monthsToMove > maxMonthsInFuture) { throw new ArgumentException($"Cannot compute flight prices which are more than {maxMonthsInFuture} months in the future ({date})!"); } var dateInput = await GetElementByClassPrefix(browser, "button", "DateInput_DateInput__").ConfigureAwait(false); await dateInput.Click().ConfigureAwait(false); var monthSelectorClasses = await GetClassesWithPrefixNameScript()(browser, "select", "BpkSelect_bpk-select__").ConfigureAwait(false); var monthSelector = await browser.GetElementByClass(monthSelectorClasses.Last()).ConfigureAwait(false); foreach (var month in Enumerable.Range(0, monthsToMove)) { await MoveOneMonthDown().ConfigureAwait(false); } await GetDayOfMonthSelectorScript()(browser, date.Day).ConfigureAwait(false); async Task MoveOneMonthDown() { await monthSelector.SendEnter().ConfigureAwait(false); await browser.SendDownArrowKey().ConfigureAwait(false); await monthSelector.SendEnter().ConfigureAwait(false); } }