0

When I am printing the cause of TimeoutException caused by NoSuchElementException as in :

catch (TimeoutException tox) {
            tox.printStackTrace();
            printWarn("Cause for failure => " + tox.getCause());
}

The output to what I get from this is as follows :

Cause for failure => org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 10.41 seconds..

Build info: version: '2.48.2', revision: '41bccdd10cf2c0560f637404c2d96164b67d9d67', time: '2015-10-09 13:08:06' System info: host: 'localhost', ip: '172.20.44.84', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.10.5', java.version: '1.8.0_65'

Driver info: AppiumDriver

Capabilities [{....}]

Session ID: 405d7843-5353-4a96-9288-b6d8301651b5

* **Element info: {Using=id, value=et_mobile_editTextView}

Can I get all the information in bold separately using any property or appending any method that I might be unaware of?

What I currently have is :

String completeCause = tox.getCause();

What I am looking for is :

String buildInfo = tox.<somemethod>();
String driverInfo = tox.<somemethod>(); etc..

Thanks in advance for taking out your time to help me with this.

Naman
  • 27,789
  • 26
  • 218
  • 353

1 Answers1

2

The Selenium JavaDoc for TimeOutException shows methods getAdditionalInformation, getBuildInformation, getDriverName, getSystemInformation which will give you all your needed information separately.

catch(TimeoutException tox) {
  tox.printStackTrace();
  String driverName = tox.getDriverName();
  BuildInfo buildInfo = tox.getBuildInformation();
  ...
}

Element info is hidden in getAdditionalInformation. Looking at the source code of WebDriverException (which your exception is inheriting from) the information is stored in a private map. However, the information is seperated by \n which will give you the possibility to filter those entries and just search for the one with Element Info.

It could look like this (not tested, just written down)

String[] additionalInformation = tox.getAdditionalInformation().split("\n");

for(String s : additionalInformation) {
  String[] part = s.split(":");
  if("Element Info".equals(part[0]) {
    String elementInfo = part[...]; //you need to investigate the right output of the split
  }
}

[old post]

As I see TimeOutException.getCause() will return a Throwable which is in this case a NoSuchElementException. Seleniums JavaDoc reveals that there are methods getDriverName and getSystemInformation.

catch (TimeoutException tox) {
    tox.printStackTrace();
    if(tox.getCause() instanceof NoSuchElementException) {
      NoSuchElementException nse = (NoSuchElementException) tox.getCause();
      ...
    }
}
lschuetze
  • 1,218
  • 10
  • 25
  • went through the docs and am able to get Driver and System Info separately, but couldn't find a method for `Element info` and the information provided in the cause is what I want to breakdown into pieces – Naman Jan 20 '16 at 05:50
  • Already took a look at [TimeoutException JavaDoc](https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/TimeoutException.html)? There are methods `getSystemInformation` and `getAdditionalInformation`. Even `getDriverName` etc. Seems the cast to `NoSuchElementException` is not necessary here. – lschuetze Jan 20 '16 at 05:55
  • @Ischuetze : didn't get you there – Naman Jan 20 '16 at 06:02
  • that's what I meant when I said I have tried these but couldn't find a method for `Element info` – Naman Jan 20 '16 at 06:06
  • Added code example and link to source code of the exception where you can see the details. – lschuetze Jan 20 '16 at 06:31