Can't able to locate Web Element using xpath

I want to click on + icon, which state name is having attribute as data-stateid=1,

But when I try to find web element using firepath.
All + icon is having the same attribute as class so, I'm not able to click on specific + icon.

HTML Code:

<div class="panel-heading">
 <h4 class="panel-title">
  <a data-toggle="collapse" href="#lob1" data-stateid="1">
   <span class="tag tag-default tag-pill pull-xs-right">0</span>
    <i class="fa fa-plus pull-xs-right btn-country-list" onclick="GetLobPopUp('AL','Alabama')"/>
 </h4>
</div>
<div id="lob1" class="panel-collapse collapse in" style="height: auto;">
 <div class="panel-heading">
  <h4 class="panel-title">
   <a data-toggle="collapse" href="#lob3" data-stateid="3">
    <span class="tag tag-default tag-pill pull-xs-right">0</span>
     <i class="fa fa-plus pull-xs-right btn-country-list" onclick="GetLobPopUp('AZ','Arizona')"/>
 </h4>
</div>
<div id="lob3" class="panel-collapse collapse in" style="height: auto;">
 <div class="panel-heading">
  <h4 class="panel-title">
   <a data-toggle="collapse" href="#lob4" data-stateid="4">
    <span class="tag tag-default tag-pill pull-xs-right">0</span>
     <i class="fa fa-plus pull-xs-right btn-country-list" onclick="GetLobPopUp('AR','Arkansas')"/>
  </h4>
</div>

Can anyone help me on this issue?
Best Regards.

Upvotes: 2

Views: 97

Answers (2)

kieraf
kieraf

Reputation: 96

You can try this query:

//h4[./a[@data-stateid=1]]/i

(tested on http://xpather.com/9pCZr2I0)

The pasted HTML seems a bit malformed so I corrected it.

Upvotes: 2

becixb
becixb

Reputation: 373

All you need to do is identify the element first with using different attributes.. if you can't use class, then use data-stateid:

//a[@data-stateid='1']/following-sibling::i

Upvotes: 3

Related Questions