I have a number of tests I'm running through Selenium. Whenever one fails I just have a catch surrounding the test saying that an Element could not be found.
It seems quite vague instead I want to be able to say what element can't be found and write that to my error log. Is there a way to determine what element cannot be found?
Here is some example code I am using at the moment to catch my error.
try
{
base.SetUp();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(
excelSession.FindElementByName("Blank workbook"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(
excelSession.FindElementByName("Create"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(
excelSession.FindElementByName("New"))).Click();
webDriverWait.Until(ExpectedConditions.ElementToBeClickable(
excelSession.FindElementByName("E Sample Data"))).Click();
CommonMethods.IsElementDisplayed(excelSession,
new StackTrace(true).GetFrame(0).GetFileLineNumber(),
new StackTrace(true).GetFrame(0).GetMethod(), "CreateErrorIcon",
"Error appeard while selecting the E Sample Data button");
}
catch (Exception)
{
CommonMethods.ExceptionHandler("Couldn't find element",
new StackTrace(true).GetFrame(0).GetFileLineNumber(),
new StackTrace(true).GetFrame(0).GetMethod(), excelSession);
}