Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This will work:</p> <pre><code>//*[@id=\"Navigation\"]/descendant::span[text()='Matrices'] </code></pre> <p>Note that if you can, be specific in your XPath queries, mainly to aid readability and improve performance...that is the <code>*</code> in your query will query <strong>all</strong> elements in the page. I don't know what kind of element the <strong>Navigation</strong> element is, but you should put it's exact element type in, for instance if it's a div, make it:</p> <pre><code>//div[@id=\"Navigation\"]/descendant::span[text()='Matrices'] </code></pre> <p>A slight explanation for this XPath is that it will grab the <code>Navigation</code> element, and simply look <em>anywhere inside it</em> to find a <code>span</code> element that has the text of <code>Matrices</code>. Without the <code>descendant</code> bit in the XPath, it would only search for <strong>direct children</strong>. That means elements that a child of <code>Navigation</code>, nothing else - so if an element is a child of <code>TestDiv</code> which is a child of <code>Navigation</code>, <code>descendant</code> would catch it, without it you won't return any results.</p> <p>As for why <code>By.PartialLinkText</code> would not work, this would only search for anchor links. It is common, as you have seen, that anchor links have a <code>span</code> element inside them or sometimes it is just a <code>span</code> on it's own.</p> <p><code>By.PartialLinkText</code> and similarly <code>By.LinkText</code> would not 'see' this element, since it's not an anchor element.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload