Chan Chi Lam
Chan Chi Lam

Reputation: 35

Jxbrowser: Get parent element of my element

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>

Upvotes: 2

Views: 190

Answers (1)

Mehran Torki
Mehran Torki

Reputation: 987

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

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

Upvotes: 1

Related Questions