Java 是否有办法将异常原因中提供的信息分开?
当我打印由NoTouchElementException引起的TimeoutException原因时,如中所示:Java 是否有办法将异常原因中提供的信息分开?,java,exception,exception-handling,stack-trace,catch-block,Java,Exception,Exception Handling,Stack Trace,Catch Block,当我打印由NoTouchElementException引起的TimeoutException原因时,如中所示: catch (TimeoutException tox) { tox.printStackTrace(); printWarn("Cause for failure => " + tox.getCause()); } 我从中得到的输出如下: 故障原因=>org.openqa.selenium.NoSuchElementExcep
catch (TimeoutException tox) {
tox.printStackTrace();
printWarn("Cause for failure => " + tox.getCause());
}
我从中得到的输出如下:
故障原因=>org.openqa.selenium.NoSuchElementException:An
在使用给定搜索的页面上找不到元素
参数。(警告:服务器未提供任何堆栈跟踪。)
(资料)
命令持续时间或超时:10.41秒
构建信息:版本:“2.48.2”,修订版:
“41bccdd10cf2c0560f637404c2d96164b67d9d67”,时间:“2015-10-09
13:08:06'
系统信息:主机:'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'
驾驶员信息:AppiumDriver
功能[{..}]
会话ID:405d7843-5353-4a96-9288-b6d8301651b5
***元素信息:{Using=id,value=et\u mobile\u editTextView}
我是否可以使用任何属性或附加任何我可能不知道的方法分别以粗体显示所有信息
我目前拥有的是:
String completeCause = tox.getCause();
我要找的是:
String buildInfo = tox.<somemethod>();
String driverInfo = tox.<somemethod>(); etc..
String buildInfo=tox.();
字符串驱动程序rinfo=tox.();等
提前感谢您抽出时间来帮助我。Selenium JavaDoc for shows methodsgetAdditionalInformation
、getBuildInformation
、getDriverName
、getSystemInformation
将分别为您提供所需的所有信息
catch(TimeoutException tox) {
tox.printStackTrace();
String driverName = tox.getDriverName();
BuildInfo buildInfo = tox.getBuildInformation();
...
}
元素信息隐藏在getAdditionalInformation
中。查看WebDriverException
(您的异常继承自该异常)的列表,该信息存储在私有映射中。但是,信息由\n
分隔,这将使您可以筛选这些条目,只需搜索包含元素信息的条目
它可能看起来像这样(没有测试,只是写下来)
[旧帖] 正如我看到的
TimeOutException.getCause()
将返回一个Throwable
,在本例中它是一个NoTouchElementException
。显示有方法getDriverName
和getSystemInformation
catch (TimeoutException tox) {
tox.printStackTrace();
if(tox.getCause() instanceof NoSuchElementException) {
NoSuchElementException nse = (NoSuchElementException) tox.getCause();
...
}
}
查看了文档,我能够分别获取驱动程序和系统信息,但找不到
元素信息的方法,原因中提供的信息是我想要分解为多个部分的内容准备好了吗?有方法getSystemInformation
和getAdditionalInformation
。即使是getDriverName
等,这里似乎也不需要对NoSuchElementException
进行强制转换。@Ischuetze:没有让你明白这就是我所说的,我已经尝试了这些,但找不到元素信息的方法
添加了代码示例,并链接到异常的源代码,在那里你可以看到详细信息。
catch (TimeoutException tox) {
tox.printStackTrace();
if(tox.getCause() instanceof NoSuchElementException) {
NoSuchElementException nse = (NoSuchElementException) tox.getCause();
...
}
}