protected virtual void HandleTimeoutException(WebDriverTimeoutException ex, DesiredState desiredState, By locator, List <IWebElement> foundElements, string name = null) { var message = string.IsNullOrEmpty(name) ? $"No elements with locator '{locator}' were found in {desiredState.StateName} state" : $"Element [{name}] was not found by locator '{locator}' in {desiredState.StateName} state"; if (desiredState.IsCatchingTimeoutException) { if (!foundElements.Any()) { if (desiredState.IsThrowingNoSuchElementException) { throw new NoSuchElementException(message); } Logger.Debug("loc.no.elements.found.in.state", null, locator.ToString(), desiredState.StateName); } else { Logger.Debug("loc.elements.were.found.but.not.in.state", null, locator.ToString(), desiredState.StateName); } } else { if (desiredState.IsThrowingNoSuchElementException && !foundElements.Any()) { throw new NoSuchElementException($"{message}: {ex.Message}"); } throw new WebDriverTimeoutException($"{ex.Message}: {message}"); } }
private void HandleTimeoutException(WebDriverTimeoutException ex, ElementStates elementState, By selector, List <IWebElement> foundElements) { var message = $"No elements with selector '{selector}' were found in {elementState.StateName} elementState"; if (elementState.IsCatchingTimeoutException) { if (!foundElements.Any()) { if (elementState.IsThrowingNoSuchElementException) { throw new NoSuchElementException(message); } Logger.Instance.Debug($"No elements with selector '{selector}' were found in {elementState.StateName} elementState"); } else { Logger.Instance.Debug($"Elements were found by selector '{selector}' but not in elementState {elementState.StateName}"); } } else { var combinedMessage = $"{ex.Message}: {message}"; if (elementState.IsThrowingNoSuchElementException && !foundElements.Any()) { throw new NoSuchElementException(combinedMessage); } throw new WebDriverTimeoutException(combinedMessage); } }