0

当我打印由 NoSuchElementException 引起的 TimeoutException 的原因时,如下所示:

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

我从中得到的输出如下:

失败原因 => org.openqa.selenium.NoSuchElementException:使用给定的搜索参数无法在页面上找到元素。(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:10.41 秒..

构建信息:版本:'2.48.2',修订:'41bccdd10cf2c0560f637404c2d96164b67d9d67',时间:'2015-10-09 13:08:06' 系统信息:主机:'localhost',ip:'172.20.44.84',os。名称:'Mac OS X',os.arch:'x86_64',os.version:'10.10.5',java.version:'1.8.0_65'

驱动程序信息:AppiumDriver

能力[{....}]

会话 ID:405d7843-5353-4a96-9288-b6d8301651b5

* **元素信息:{Using=id, value=et_mobile_editTextView}

我可以使用任何属性或附加任何我可能不知道的方法单独获取所有粗体信息吗?

我目前拥有的是:

String completeCause = tox.getCause();

我正在寻找的是:

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

提前感谢您抽出时间来帮助我。

4

1 回答 1

2

TimeOutException的 Selenium JavaDoc显示了方法getAdditionalInformationgetBuildInformationgetDriverNamegetSystemInformation它们将分别为您提供所有需要的信息。

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

元素信息隐藏在getAdditionalInformation. 查看(您的异常继承自)的源代码,信息存储在私有映射中。WebDriverException但是,信息是分开的,\n这将使您可以过滤这些条目并仅搜索具有Element Info的条目。

它可能看起来像这样(未经测试,只是写下来)

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
  }
}

[旧帖]

如我所见,TimeOutException.getCause()将返回 aThrowable在这种情况下为 a NoSuchElementExceptionSeleniums JavaDoc揭示了方法getDriverNamegetSystemInformation.

catch (TimeoutException tox) {
    tox.printStackTrace();
    if(tox.getCause() instanceof NoSuchElementException) {
      NoSuchElementException nse = (NoSuchElementException) tox.getCause();
      ...
    }
}
于 2016-01-20T04:09:34.870 回答