tags:

views:

29

answers:

1

In following 2 snippets of html code, I'm trying to create xpath or css for finding if span(Element1 in snippet 1 and Element 2 in snippet 2) are highlighted(preselected) when page is loaded

Snippet 1:

<div id="idc" class="tre">
  <ul id="idCatT_srt_ul" class="abc">
    <li class="treN treB treSelected" title="Element1 title">
      <span class="spclass">Element1</span>
    </li>
  </ul>
</div>

Snippet 2:

<div id="idA" class="tre" >
 <ul id="idAc_srt_ul" class="treChi treRtChil">
  <li class="treeN treB treeLast treSelected" title="Element 2 Title">
    <span>Element 2 Text</span>
  </li>
 </ul>
</div>
+1  A: 

If the treSelected class attribute value denotes that it is preselected, then the following XPATH statement would work:

span[parent::li[contains(@class,'treSelected')]]

It will match on span elements who's parent is an li element that contains a class attribute that contains 'treSelected'.

Mads Hansen
Hey Mads, Thank you for your reply. However it seems not working. I wrote like this :String selected= selenium.getText("//span[parent::li[contains(@class,'treSelected')]]")println(sele)can you tell me two different xpaths or css based on unique div id for each snippet?
doneright
sorry, ignore my earlier comment regarding not working. It works and find only selected item from snippet 1. Remember both html snippets above exists on same page so both spans are preselected(highlighted)
doneright