1
jOOX可以用来发现使用这样的元素的XPATH:我可以使用jOOX来查找属性的xPath吗?
Element element = (Element) someNode;
String xPath = $(element).xpath();
我可以做同样的属性?我试过这个:
Attr attr = (Attr) someAttributeNode;
String xPath = $(attr).xpath();
但它返回null。
编辑:我已经成功从节点的XPath和属性的名称创建我自己的XPath来解决它,但它好像我不应该这样做。下面是完整的解决方法:
Element element = (Element) someNode;
String elementXpath = $(element).xpath();
String attributeName = someAttributeNode.getNodeName();
String attributeXpath = elementXpath + "/@" + attributeName; // <-- work around
创建自己的xpath更好,也是优化的 – chaosguru