Jxbrowser: Get parent element of my element

185 views Asked by At

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>
1

There are 1 answers

0
Mehran Torki On BEST ANSWER

Cast DOMNode to DOMElement and use it's .getAttribute(String attr):

String href = ((DOMElement)(img.getparent())).getAttribute("href");