selenium webdriver - Xpath get element above -


suppose have structure:

<div class="a" attribute="foo">     <div class="b">         <span>text example</span>     </div> </div> 

in xpath, retrieve value of attribute "attribute" given have text inside: text example

if use xpath:

.//*[@class='a']//*[text()='text example'] 

it returns element span, need div.a, because need value of attribute through selenium webdriver

hey there lot of ways can figure out.

so lets text example given, can identify using text:-

//span[text()='text example']/../..         --> if know 2 level 

or

//span[text()='text example']/ancestor::div[@class='a']  --> if don't know how many level `div` 

above 2 xpaths can used if want identify element using text example, if don't want iterate through text. there simple ways identify directly:-

//div[@class='a'] 

Comments

Popular posts from this blog

gridview - Yii2 DataPorivider $totalSum for a column -

java - Suppress Jboss version details from HTTP error response -

Sass watch command compiles .scss files before full sftp upload -