Skip to main content

Finding returns element references for the other element commands. Paths follow http://127.0.0.1:4445/{token}; see the overview for the reply format and the errors.

Locator strategies#

usingFinds
css selectorquerySelector and querySelectorAll.
xpathThe element nodes of document.evaluate, in document order, evaluated from the root.
link texta elements whose innerText, trimmed, equals value.
partial link texta elements whose innerText contains value.
tag namegetElementsByTagName.
Verified on macOS: css selector Not run on a real app yet: xpath, link text, tag name

Any other using answers 400 invalid argument (unknown locator strategy `...`), and a selector or XPath the page cannot parse 400 invalid selector, with the page’s own message.

Under the session’s implicit wait, finding looks again every 50 ms while nothing matches, until the wait is over (the default, 0, looks once).

Find element#

POST /session/{sessionId}/element

Verified on macOS

The first match in the current frame’s document (see Frames).

sessionIdstringrequired#

The current session’s id.

usingstringrequired#
valuestringrequired#

The selector, XPath, link text or tag name.

valueobjectrequired#

The element’s reference.

Errors

StatuserrorWhen
400invalid argumentusing or value is missing or not a string; an unknown strategy.
400invalid selectorThe page cannot parse the selector or the XPath.
404no such elementNothing matched before the implicit wait was over.
404no such frameThe frame entered is gone or no longer same-origin.

Find elements#

POST /session/{sessionId}/elements

Verified on macOS

Every match in the current frame’s document, in document order. Nothing matched is an empty array, not an error.

sessionIdstringrequired#

The current session’s id.

usingstringrequired#
valuestringrequired#

The selector, XPath, link text or tag name.

valueobject[]required#

The elements’ references, possibly none.

Find element from element#

POST /session/{sessionId}/element/{elementId}/element

The first match inside an element. An XPath is evaluated with the element as its context node, so .// looks inside it and // in the whole document.

sessionIdstringrequired#

The current session’s id.

elementIdstringrequired#

The id of the element to search in.

usingstringrequired#
valuestringrequired#

The selector, XPath, link text or tag name.

valueobjectrequired#

The element’s reference.

Errors

As Find element, and 404 no such element or 404 stale element reference when elementId is unknown or gone.

Find elements from element#

POST /session/{sessionId}/element/{elementId}/elements

Every match inside an element; an empty array when none.

sessionIdstringrequired#

The current session’s id.

elementIdstringrequired#

The id of the element to search in.

usingstringrequired#
valuestringrequired#

The selector, XPath, link text or tag name.

valueobject[]required#

The elements’ references, possibly none.

Get active element#

GET /session/{sessionId}/element/active

The current frame’s focused element (document.activeElement), or its body when nothing has the focus.

sessionIdstringrequired#

The current session’s id.

valueobjectrequired#

The element’s reference.