Description
Returns an array of web page elements that match the specified group of CSS selectors. To search for an individual element, use the QuerySelector
method.
Declaration
TestObj.QuerySelectorAll(Selector)
TestObj | A variable, parameter or expression that specifies a reference to one of the objects listed in the Applies To section | |||
Selector | [in] | Required | String | |
Result | An array of the tested objects. |
Applies To
View Mode
To view this method in the Object Browser panel and in other panels and dialogs, activate the Advanced view mode.
Parameters
The method has the following parameter:
Selector
A string containing one or more CSS selectors separated by commas.
The table below demonstrates some examples of CSS selectors which you can pass to the QuerySelectorAll
method in order to search for the desired web page elements.
Selector | Description |
---|---|
h3 |
All H3 elements. |
#infobox |
An element with the ID "infobox". |
.nav |
All elements with the class "nav". |
div,p |
All DIV elements and all P elements. |
div p |
All P elements inside DIV elements. |
img.thmb |
All IMG elements of the "thmb" class. |
a:link |
All unvisited links. |
a[target=_blank] |
All links that open in a new window. |
a[src^="https"] |
All links whose src attribute value begins with "https". |
li:first-of-type |
All LI elements that are the first item in their parent elements. |
p:nth-child(2) |
All P elements that are located at the second position within their parent elements. |
You can find more information about the CSS selector syntax in the Finding Web Objects Using CSS Selectors topic. For a complete reference, see the W3C Selectors Level 3 Specification.
Result Value
An array of the objects that match the specified selector(s).
Tip: | To search for an individual element, use the QuerySelector method. |
If a TestComplete web object matches the specified selector, then the array item contains this object.
If there is no matching TestComplete test object, the array item holds the appropriate HTML object.
If neither matching test objects, nor HTML objects were found, the method returns an empty array.
Note for JScript, C#Script and C++Script users: The returned array is Variant-compatible. It can be used as is in JavaScript, Python, VBScript and DelphiScript, but if you use JScript, C#Script or C++Script, you have to convert this array to the format supported by the JScript engine. To do this, you can use the toArray()
method of the variant array:
JScript, C#Script, C++Script
var JScript_Array = Variant_Array.toArray()
Remarks
-
In cross-platform web tests, we recommend that you use the
FindElement
(orWaitElement
) method instead. -
When the method is called for
Page
objects, it searches the entire web page. If it is called for a particular web page element, then it searches within the children of that element. When the method is called for theUIPage
object or its child objects, the search is performed within the UI controls. -
The search is performed within the current web page. If the tested web page contains HTML frames displaying other web pages, then to search for the desired element within a frame, you should call
Frame.QuerySelectorAll()
instead ofPage.QuerySelectorAll()
. -
If the selector string contains a CSS pseudo-element (
:after
,:before
,::first-letter
,::first-line
,::selection
), the method returns an empty array.
Example
To view the example that demonstrates how you can use the QuerySelectorAll
method to search for a web page elements, see Finding Web Objects Using CSS Selectors.
See Also
QuerySelector Method (Page Objects)
Classic Web Testing
Find Web Objects
NativeWebObject.Find Method (Page Objects)
Find Method
FindAll Method
FindChild Method
FindAllChildren Method
EvaluateXPath Method (Page Objects)