Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8782191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:30:42+00:00 2026-06-13T20:30:42+00:00

Given following markup <div> <a>Username1</a> </div> <div> <button>Unblock</button> </div> <div> <a>Username2</a> </div> <div> <button>Unblock</button>

  • 0

Given following markup

<div>
    <a>Username1</a>
</div>
<div>
    <button>Unblock</button>
</div>
<div>
    <a>Username2</a>
</div>
<div>
    <button>Unblock</button>
</div>
<div>
    <a>Username3</a>
</div>
<div>
    <button>Unblock</button>
</div>

How do I select button element which is a cousin of a element with text Username2?

I can select the a element with //a[contains(., 'Username2')], so I thought that //a[contains(., 'Username2')]/following-sibling::/div/button would select the correct button, but that does not work. I think that it’s not even valid XPATH.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T20:30:43+00:00Added an answer on June 13, 2026 at 8:30 pm

    You were close:

    //a[contains(., 'Username2')]/../following-sibling::div[1]/button
    

    To navigate to the cousin you first have to go to the parent (..) and then to its sibling.

    Note that the following-sibling:: axis selects all following siblings, not only the first one. This means you must use [1] if you just want the first.

    This would also work:

    //a[. = 'Username2']/../following-sibling::div[1]/button
    

    So would this:

    //div[a = 'Username2']/following-sibling::div[1]/button
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following html markup : <div> <span id=391d0e73-d491-4e55-9ccb-b74c6923e070>This is a text element</span>
Given the following markup: <div class=foo> <!-- comments --> some junk content <input type=button
Given the following markup <!DOCTYPE HTML PUBLIC -//W3C//DTD HTML Strict//EN><META http-equiv=Content-Type content=text/html; charset=utf-8> <HTML
Given the following XAML markup, I would expect the text in the Hyperlink to
Given the following markup. <div id=example> <div> <div> <input type='hidden'></input> </div> </div> </div> How
Given following Statment: String query = "Select * from T_spareParts where SparePartPK IN (?
Given the following mark-up... <div id=Header> <a href=# class=Highlight>foo</a> </div> And the following stylesheet...
given the following markup <ul class=ulGreen> <li><b>On-Board systems - Road Vehicle</b><span style=color:black;> (See an
Given the following markup for a GridView column, why are my image buttons showing
Given the following markup <ul class=list> <li>first item</li> ​<li class=item>second item</li> <li>third item</li> </ul>​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.