Is there any way directly get the parent element to find its attributes? In my situation, I have a DOMElement img,I have to use functions
img.getparent().getparent().findElement(By.tagName("a")).getAttribute("href"));
and the result is not accuarate since a parent node can find many same type of elements
<td>
<a href=""><img></img></a>
<a></a>
<a></a>
<a></a>
<a></a>
</td>
Cast DOMNode
to DOMElement
and use it's .getAttribute(String attr)
:
String href = ((DOMElement)(img.getparent())).getAttribute("href");