Selectors
Answers on selecting elements with XPath, CSS selectors, class names, attributes, text, and DOM relationships.
4 answers
What are CSS attribute selectors and what's the syntax?
CSS attribute selectors target elements by attribute value using bracket syntax. Operators cover presence, exact match, prefix, suffix, and substring.
Apr 28, 2026
How do you use XPath to find an element that contains specific text?
Use contains() in XPath to match partial text. Prefer contains(., 'value') over contains(text(), 'value') when the element has nested tags or split labels.
Apr 28, 2026
Is there a CSS selector that matches an element by the text it contains?
CSS has no selector that matches an element by its text content. Use a data-* attribute selector, JavaScript textContent, or XPath contains() instead.
Apr 28, 2026
What does preceding-sibling do in XPath?
preceding-sibling:: selects sibling nodes before the context node under the same parent. Index [1] is the closest sibling, not the first in document order.
Apr 28, 2026