You can create extension methods for directly asserting elements.
There you can wrap the assert statements with a try catch. In the catch, you can add the exception message to a log if you have one.
public static class SafeAssertExtensions
{
public static void AreEquals(this IWebElement element, string expectedText)
{
try
{
if (element.Text == null)
{
throw new NullReferenceException("The element text property is null.");
}
Assert.AreEquals<string>(element.Text, expectedText, "The text- {0} was not as expected- {1}", element.Text, expectedText);
}
catch (Exception ex)
{
Log.WriteLine();
}
}
}
You can add similar methods for the other types of validations.
You can use it directly over your elements.
textFieldElement.AreEquals("your sample text content");