How to use preceding sibling in xpath

Here i want to Accept button. Here is the HTML.

<div class="friend-request no-pad ng-scope" ng-if="notifications.friendInvites.length > 0">
<p class="rem-head mzero small">
<div class="reminder-lst lst-box ng-scope" ng-repeat="friendInvite in notifications.friendInvites | limitTo:limit">
<span class="img-frame img-circle">
<span class="pull-left rem-detail-a">
<a class="pull-left rem-detail-a pzero" href="friend#/friends/friendprofile/b6c70e4f-bfe1-440d-836c-2e8fdc88540e">
<span class="frndact pull-right">
<a class="ignore" ng-click="ignoreNotification(friendInvite, 'friend')" href="javascript:void(0)">
<a class="accept" ng-click="acceptNotification(friendInvite, 'friend')" href="javascript:void(0)">
<i class="fa fa-lg fa-check-circle green"></i>
</a>

I have tried using below xpath but not working. Can anyone plz help me?

@FindBy(xpath=".//a[ng-click='acceptNotification(friendInvite, 'friend')']/preceding-sibling::i[@css='.fa.fa-lg.fa-check-circle.green']").

Thanks in advance

Answers


Assuming that you are looking for the 'A' tag of class accept, you can try

//i[@class="fa fa-lg fa-check-circle green"]/preceding-sibling::a[@class="accept"]

or

//i[@class="fa fa-lg fa-check-circle green"]/preceding-sibling::a[@ng-click="acceptNotification(friendInvite, 'friend')"]

a couple of things:

  • as TT noted your xpath was missing the @ for the attribute selector
  • the sample you posted is not a well formed xml, expect troubles with xpath if you don't have an xhtml compliant source.
  • if you use the second example mind to escape either the " or the ' quotes, if you use it inside another expression

Need Your Help

Can I skip cmake compiler tests or avoid "error: unrecognized option '-rdynamic'"

c cmake cross-compiling

compilation options for cmake (on windows) for ARM target system but when I run configure it's starting compiler tests: