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 581815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:37:13+00:00 2026-05-13T14:37:13+00:00

This is my first post here and since I’ve seen many great answers I

  • 0

This is my first post here and since I’ve seen many great answers I thought I’d give it a try.

I’m trying to use XPath to obtain a specific element in an HTML document. Here is an example based off of the Google web page:

<html>
  <head>
    <title>XPath Test</title>
  </head>
  <body>
    <form name='f'>
      <table>
        <tbody>
          <tr>
            <td>
              <input name='q' type="text" />
            </td>
          </tr>
        </tbody>
      </table>
    </form>
  </body>
</html>

Using the example above (which is simplified for the purposes of asking for help), I would like to be able to find the input element whose name=’q’ and who has an ancestor who is 5 parents up with the name=’f’.

For example if I were to do this in the syntax of S.W.A.T. which is an open-source web automation testing library located at http://ulti-swat.wikispaces.com, the syntax would be as follows:

|AssertElementExists|Expression|name=q;parentElement.parentElement.parentElement.parentElement.parentElement.name=f|input|

I just started learning XPath and am trying to understand how to combine predicates with axes. Is it possible to do expressions like this with XPath? If so can someone knowledgeable please help?

  • 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-05-13T14:37:14+00:00Added an answer on May 13, 2026 at 2:37 pm

    You could to do:

    //input[@name='q' and ancestor-or-self::*[@name='f']]
    // -- input element whose name='q' and who has an ancestor with the name='f'
    

    or

    //input[@name='q' and ../../../../../../*[@name='f']]
    // -- input element whose name='q' and who is 5 parents up with the name='f'
    

    You can use this desktop XPath Visualizer to test your XPath expressions. A basic tutorial can be found here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
Well, this is my first post here and really enjoying the site. I have
this is my first question to stackoverflow so here it goes... I use cruise
My first post on this site with huge hope:: I am trying to understand
This is my first post and I'm quite a novice on C++ and compiling
this is my first question here so I hope I can articulate it well
This is my first post, so please be gentle. I've been playing around with
This is my first post on StackOverflow. This community has provided me with some
Hey everyone, this is my first post up on StackOverflow! WOO! Anyhow, onto my
I've been scratching my head since my first VHDL class and decided to post

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.