What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Use the asterisk (*) as an XPath node test to match elements without naming their tags. In a child step, * selects the current node’s element children; //* selects descendant elements throughout the document. The right expression depends on the context node, the axis, and whether you mean elements or attributes.
What the XPath wildcard selects
XPath expressions are made of steps. A step has an axis, which describes the relationship to the current context node, and a node test, which identifies what kind of node to match. The wildcard is the node test *. It matches the principal node kind for the step’s axis: on the child axis, that means elements; on the attribute axis, it means attributes.
So * does not mean “every node everywhere.” In a child step it means “any element child here,” while the axis and expression determine the scope. This axis-sensitive behavior is specified by the World Wide Web Consortium’s XPath 3.1 specification.
Common expressions at a glance
| Expression | What it selects | Typical use |
|---|---|---|
* |
Element children of the current context node | Inspect one level below the current node |
./* |
Element children relative to the current context node | Make the relative context explicit |
/* |
Element children of the document node | Select the document element |
//* |
Descendant elements beneath the document node | Search through the document tree |
@* |
All attributes on the current element | Inspect an element’s attributes |
Choose the right scope: children or descendants
Use a child step when you know the match is one level down. Use a descendant step when the target may occur at any depth. Broad descendant searches can return many matches, so narrow them with a known ancestor or predicate when possible.
#1 Best Overall
Select any child element
* is shorthand for child::* in a location step. It matches all element children of the current context node, regardless of tag name. The explicit form can make complex expressions easier to read:
*— any element child of the current context node.child::*— the same selection, with the axis written out../*— explicitly begin from the current context node, then select its element children.
For example, if the context is a section element, ./* matches its immediate element children, not every element nested inside them.
Select descendants at any depth
The // abbreviation uses the descendant-or-self axis followed by a child step. From the document context, //* therefore selects descendant elements throughout the document. The long form is descendant::* when evaluated from the current context node; it selects descendants, but not the context node itself.
Quick wins for a faster PC:
Scan for outdated or missing drivers - takes under a minuteDriver Scan →Clear out junk files and repair common Windows errorsFree Scan →Rank #2
- Used Book in Good Condition
//*— descendant elements from the document context.//section/*— element children of each matchingsectiondescendant.descendant::*— all descendant elements relative to the current context node.
In a browser or automation script, the context node matters. An expression evaluated against a particular element does not have the same starting point as one evaluated against the document.
Use predicates when the tag name is unknown
The wildcard broadens the node test; a predicate can still filter matches by a known property. This is useful when markup uses an unknown or changing tag name but exposes a stable attribute.
//*[@id]selects descendant elements with anidattribute.//*[@data-role='dialog']selects descendant elements whosedata-roleattribute isdialog.//*/buttonselectsbuttonchildren of any element matched along the path; if the goal is simply every button descendant,//buttonis more direct.
Predicates use XPath rules for values and context. For example, attribute existence is written [@id]; attribute equality is written [@data-role='dialog']. Prefer the narrowest expression that expresses the target so that unrelated matches do not make automation ambiguous.
Select attributes with the attribute wildcard
To select attributes rather than elements, use the attribute axis. The abbreviated form is @*, equivalent to attribute::*. It returns every attribute on the current context element; it does not select the element’s children or attributes belonging to descendants.
For example, if the context node is a particular element, @* matches attributes such as id, class, and data-state when they are present. To find elements that have any attribute, use an element expression with a predicate such as //*[@*]. The distinction is important: @* selects attribute nodes, whereas //*[@*] selects descendant element nodes that carry at least one attribute.
Handle namespaces when matching elements
In XML and SVG, element names may belong to namespaces. A plain wildcard ignores the element name, so it can match elements across namespaces. XPath 3.1 also defines namespace-aware wildcard forms for cases where you want to constrain either the namespace URI or the local name.
ns:*matches any local name in the namespace bound to the prefixns.*:itemmatches the local nameitemin any namespace.Q{urn:example}*matches any local name in the namespace URIurn:example.
Namespace prefixes must be resolved in the XPath evaluator’s static context. In browser JavaScript, provide a namespace resolver to Document.evaluate() when the expression uses a prefix. A prefix in an XPath expression is not automatically resolved just because the source document uses that prefix: the evaluator needs the mapping.
These namespace wildcard forms are XPath 3.1 syntax. Do not assume every browser API or automation binding supports every XPath 3.1 feature. Check the XPath version supported by the evaluator you are using, or use a namespace resolver and an expression supported by that implementation.
Use the wildcard in browser JavaScript
The browser DOM provides Document.evaluate() to evaluate XPath against HTML or XML documents. Its arguments include the expression, context node, namespace resolver, requested result type, and an optional reusable result object. This example asks for an ordered snapshot of all descendant elements:
Best Value
const result = document.evaluate(
'//*',
document,
null,
XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
null
);
for (let i = 0; i < result.snapshotLength; i++) {
console.log(result.snapshotItem(i));
}
To search only within a known element, pass that element as the context node and use a relative expression such as .//* for descendants or ./* for immediate element children. The result type controls how matches are returned: snapshots are convenient when you want a stable collection to iterate, while iterator result types are available for traversal. The MDN reference for Document.evaluate() documents these result types and parameters.
Use the wildcard with Selenium
Selenium WebDriver supports XPath as an element-locator strategy. In Python, for example, pass the XPath expression to By.XPATH. This complete snippet starts a Chrome session, finds all descendant elements, and closes the session:
from selenium import webdriver
from selenium.webdriver.common.by import By
# Requires Selenium and a compatible browser/driver setup.
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
elements = driver.find_elements(By.XPATH, "//*")
print(f"Found {len(elements)} descendant elements")
finally:
driver.quit()
For an actual test, replace //* with a narrower path or predicate. A wildcard locator can match many elements; where an action requires one target, assert or otherwise verify that the result is unique before interacting with it. Selenium’s locator documentation lists XPath as the strategy for locating elements that match an XPath expression.
Free tools Windows power users keep installed
One-click scans. No signup required.
Common mistakes and fixes
- Using
*when you mean all descendants:*matches only child elements on the child axis. Use.//*relative to an element context, or//*from the document context. - Assuming
//*includes attributes: it matches element nodes. Select attributes with@*on an element, or use an attribute predicate to filter elements by their attributes. - Searching from the wrong context: an expression evaluated relative to an element may not search the whole document. Pass the document as context for a document-wide search, or intentionally use a relative expression for a subtree.
- Getting too many matches: add a predicate such as
[@data-role='dialog'], or anchor the path to a meaningful ancestor. - Getting no namespace matches: verify the namespace URI and resolver mapping. A source document’s prefix does not automatically create the evaluator’s prefix mapping.
- Using XPath 3.1 syntax in a limited evaluator: namespace wildcards such as
*:itemmay not be implemented. Use syntax supported by the specific browser or WebDriver XPath engine. - Confusing element kind with schema type: XPath 3.1’s
element()andelement(*)match an element node without restricting its name or type annotation.element(*, TypeName)also constrains the schema type; it is not interchangeable with the ordinary location-step wildcard.
Or skip the browser setup
If your goal is to capture a page rather than inspect or automate its DOM, ScreenshotNeo provides a website screenshot API. It accepts a URL in one GET request and returns an image or PDF. Here is a cURL example; see the ScreenshotNeo API documentation for request options:
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot"
-d access_key=YOUR_API_KEY
--data-urlencode url=https://example.com
-o shot.webp
ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with response headers indicating the page verdict and billing status. Its MCP server offers screenshot tools for AI agents, and the free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.
When each wildcard form is useful
| Need | Use | Why |
|---|---|---|
| Immediate element children | * or ./* |
Limits the selection to one level below the context |
| Elements anywhere below a node | .//* or descendant::* |
Searches nested descendants in the current subtree |
| Document-wide descendant elements | //* |
Starts from document context and traverses descendants |
| Every attribute on an element | @* |
Uses the attribute axis, not the element child axis |
| Any element name within a namespace | ns:* or Q{uri}* |
Constrains namespace while leaving local name open |
| Known local name in any namespace | *:item |
Constrains local name while leaving namespace open |
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

