Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有没有什么办法可以直接获取父元素找到它的属性?在我的情况下,我有一个 DOMElement img,我必须使用函数
img.getparent().getparent().findElement(By.tagName("a")).getAttribute("href"));
结果不准确,因为父节点可以找到许多相同类型的元素
<td> <a href=""><img></img></a> <a></a> <a></a> <a></a> <a></a> </td>
投射DOMNode并DOMElement使用它.getAttribute(String attr):
DOMNode
DOMElement
.getAttribute(String attr)
String href = ((DOMElement)(img.getparent())).getAttribute("href");