title: XPath element which contains an attribute and whose parent's parent contains another attribute
body: <p>This is my first post here and since I've seen many great answers I thought I'd give it a try.</p>
  
  <p>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:</p>
  
  <pre><code>&lt;html&gt;
    &lt;head&gt;
      &lt;title&gt;XPath Test&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;form name='f'&gt;
        &lt;table&gt;
          &lt;tbody&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;input name='q' type="text" /&gt;
              &lt;/td&gt;
            &lt;/tr&gt;
          &lt;/tbody&gt;
        &lt;/table&gt;
      &lt;/form&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>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'.</p>
  
  <p>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 <a href="http://ulti-swat.wikispaces.com" rel="noreferrer">http://ulti-swat.wikispaces.com</a>, the syntax would be as follows:</p>
  
  <p>|AssertElementExists|Expression|name=q;parentElement.parentElement.parentElement.parentElement.parentElement.name=f|input|</p>
  
  <p>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?</p>