Is there a way to grab specific information from an exception when an exception occurs?
For example when I call printStackTrace
I get a lot of information...but sometimes I get too much information and most of it is not things I need to see since it's always the same information anyways.
At least when it comes to Selenium Webdriver, it first tells me what the problem is
com.thoughtworks.selenium.SeleniumException: Element blah not found
at org.openqa.selenium.internal.seleniumemulation.ElementFinder.findElement(ElementFinder.java:92)
at org.openqa.selenium.internal.seleniumemulation.Click.handleSeleneseCommand(Click.java:35)
at org.openqa.selenium.internal.seleniumemulation.Click.handleSeleneseCommand(Click.java:1)
at org.openqa.selenium.internal.seleniumemulation.SeleneseCommand.apply(SeleneseCommand.java:35)
at org.openqa.selenium.internal.seleniumemulation.Timer.run(Timer.java:40)
at org.openqa.selenium.WebDriverCommandProcessor.execute(WebDriverCommandProcessor.java:140)
...
Caused by: org.openqa.selenium.WebDriverException: ...
...
...
...
And then it goes on to tell me things about the my environment, capabilities (with another list of messages), and more "caused by" information.
It's a pretty long message, and I don't want it cluttering my log file. Is there a way to omit all of the "caused by" related messages?
I tried getMessage
but it only says
Element blah not found
Which is not useful. I would like to at least see which line it came from.
Sure, get only the first few stack frames and parse them. Use
getStackTrace
to get aStackTraceElement[]
and iterate through them until you get a frame in your package(or however else you want to filter) to get the correct line. The Selenium internal lines probably aren't the ones you need.On this element you can call
getMethodName
,getLineNumber
, and the like.