I currently have a solution using Selenium WebDriver and .NET Framework, using the following code to create waits for interacting with web elements as part of our automation solution.
wait = new WebDriverWait(webDriver, TimeSpan.FromSeconds(60));
This works well for waiting for an element to load in the screen, but it does not contain the most useful of message, for example if an element is not clickable the following is returned:
Message: OpenQA.Selenium.WebDriverTimeoutException : Timed out after 60 seconds
Rather than the NoSuchElement exception which identifies what record is looking to be entered.
This becomes even more of an issue when trying to validate a record value e.g.
wait.Until(webdriver => element.GetAttribute("value") == expectedValue);
As this returns the timeout issue, rather than actually declaring what the difference is, which for example a Nunit Assert will give you, here I am working around this with the following
try
{
customWait.Until(webdriver => element.GetAttribute("value") == expectedValue);
}
catch
{
// to display assertion error when unable to validate attribute in given time
Assert.AreEqual(expectedValue, element.GetAttribute("value"));
}
Is there a better way which can override the default timeout response with the original message of the internal error, e.g. after x seconds of trying to find an element return a NoSuchElement exception for the element searching for, rather than a TimeoutException.
Thanks