(网络开发新手) 你好,谁能解释一下为什么会这样
Object x=getCurrentPage().getByXPath("//div[@class = 'notification']
/text() =
'Product saved successfully'").get(0);
返回一个Boolean false
对象,但是这个
Object y = getCurrentPage().getByXPath("//div[@class='notification']
/text()").get(0);
返回带有数据DomText
对象产品保存成功
?
为什么 boolean 值为假
?在我看来它应该返回true
。
附:当我在 XPathBrowser(FF 插件)中尝试相同的查询时,它返回 boolean:true
非常感谢
最佳答案
使用:
//div[@class='notification']/text()[ . = 'Product saved successfully']
因为集合 //div[@class='notification']/text()
永远不会等于字符串“产品已保存”成功”。
正如 Alejandro 和 LarsH 指出的那样(他们都是对的),这个答案是完全错误的。重点不在于 //div[@class = 'notification']/text() = 'Product saving success'
不起作用,而只是 .get(0)
对第一个选项返回的 boolean 值没有意义(它只是声明 true
,如“该节点存在”)
关于java - xpath text() 比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4099509/