Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Short answer: it's not possible.</p> <p>Longer answer: XPath can look at HTML attributes, but it can't look at DOM properties. Selecting an <code>&lt;option&gt;</code> element in a <code>&lt;select&gt;</code> changes the <code>selected</code> <em>property</em> of the <code>&lt;option&gt;</code> to <code>true</code>, and also changes the <code>value</code> property of its parent <code>&lt;select&gt;</code> element, but it doesn't affect the attributes of either, so it is invisible to XPath.</p> <p>To find <code>&lt;option&gt;</code> elements that have the <code>selected</code> attribute set, which is often how a page author might determine which option is initially selected, you can use <code>//option[@selected]</code>. But this <em>does not</em> find the <em>currently</em> selected <code>&lt;option&gt;</code>; changes that the user makes to the selection are invisible to XPath. There's no guarantee it will even find the <em>initially</em> selected option, since it's possible that the page author didn't put the <code>selected</code> attribute on <em>any</em> elements and either let the browser select the first option by default or had some JavaScript select the initial option via the <code>selected</code> <em>property</em>.</p> <p>The multiple <a href="https://stackoverflow.com/a/17132439/1709587">other</a> <a href="https://stackoverflow.com/a/17992485/1709587">answers</a> <a href="https://stackoverflow.com/a/27642105/1709587">here</a> <a href="https://stackoverflow.com/a/15769357/1709587">claiming</a> that a selector like <code>//option[@selected]</code> can detect selection changes made by the user after the page loads are simply completely wrong.</p> <p>Of course, if you're able to use <em>CSS</em> selectors instead of XPath selectors, then <a href="https://developer.mozilla.org/en-US/docs/Web/CSS/:checked" rel="noreferrer"><code>option:checked</code></a> will do the job.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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