-
Notifications
You must be signed in to change notification settings - Fork 24
seleniumQuery Selectors
seleniumQuery allows querying elements directly by:
-
CSS Selectors -
$(".myClass")
, -
jQuery/Sizzle enhancements -
$(".myClass:eq(3)")
,$(".myClass:contains('My Text!')")
-
XPath -
$("//div/*/label/preceding::*")
- and even some own seleniumQuery selectors:
$("#myOldDiv").is(":not(:present)")
.
Our aim is to implement all CSS3 and jQuery (Sizzle) extension selectors.
Currently, most selectors both from CSS3 and jQuery extensions are supported, but not all. E.g.:
-
:contains() Selector
- Select all elements that contain the specified text.
It is worth noting that, in seleniumQuery, all CSS Selectors are translated to XPath before execution by the browser. This way, most of extended selectors won't result in a performance hit, as happens with jQuery. On the other hand, some may.
Below the jQuery selectors and, when applicable, comments about their support under seleniumQuery.
-
All Selector (“*”)
- Selects all elements. -
Attribute Contains Prefix Selector [name|="value"]
- Selects elements that have the specified attribute with a value either equal to a given string or starting with that string followed by a hyphen (-). -
Attribute Contains Selector [name*="value"]
- Selects elements that have the specified attribute with a value containing the a given substring. -
Attribute Contains Word Selector [name~="value"]
- Selects elements that have the specified attribute with a value containing a given word, delimited by spaces. -
Attribute Ends With Selector [name$="value"]
- Selects elements that have the specified attribute with a value ending exactly with a given string. The comparison is case sensitive. -
Attribute Equals Selector [name="value"]
- Selects elements that have the specified attribute with a value exactly equal to a certain value. -
Attribute Not Equal Selector [name!="value"]
- Select elements that either don’t have the specified attribute, or do have the specified attribute but not with a certain value. -
Attribute Starts With Selector [name^="value"]
- Selects elements that have the specified attribute with a value beginning exactly with a given string. -
:button Selector
- Selects all button elements and elements of type button. -
:checkbox Selector
- Selects all elements of type checkbox. -
:checked Selector
- Matches all elements that are checked or selected. -
Child Selector (“parent > child”)
- Selects all direct child elements specified by “child” of elements specified by “parent”. -
Class Selector (“.class”)
- Selects all elements with the given class. -
:contains() Selector
- Select all elements that contain the specified text. -
Descendant Selector (“ancestor descendant”)
- Selects all elements that are descendants of a given ancestor. -
:disabled Selector
- Selects all elements that are disabled. -
Element Selector (“element”)
- Selects all elements with the given tag name. -
:empty Selector
- Select all elements that have no children (including text nodes). -
:enabled Selector
- Selects all elements that are enabled. -
:eq() Selector
- Select the element at index n within the matched set. -
:even Selector
- Selects even elements, zero-indexed. See also odd. -
:file Selector
- Selects all elements of type file. -
:first-child Selector
- Selects all elements that are the first child of their parent. -
:first-of-type Selector
- Selects all elements that are the first among siblings of the same element name. -
:first Selector
- Selects the first matched element. -
:focus Selector
- Selects element if it is currently focused. -
:gt() Selector
- Select all elements at an index greater than index within the matched set. -
Has Attribute Selector [name]
- Selects elements that have the specified attribute, with any value. -
:has() Selector
- Selects elements which contain at least one element that matches the specified selector. -
:header Selector
- Selects all elements that are headers, like h1, h2, h3 and so on. -
:hidden Selector
- Selects all elements that are hidden. -
ID Selector (“#id”)
- Selects a single element with the given id attribute. -
:image Selector
- Selects all elements of type image. -
:input Selector
- Selects all input, textarea, select and button elements. -
:lang() Selector
- Selects all elements of the specified language. -
:last-child Selector
- Selects all elements that are the last child of their parent. -
:last-of-type Selector
- Selects all elements that are the last among siblings of the same element name. -
:last Selector
- Selects the last matched element. -
:lt() Selector
- Select all elements at an index less than index within the matched set. -
Multiple Attribute Selector [name="value"][name2="value2"]
- Matches elements that match all of the specified attribute filters. -
Multiple Selector (“selector1, selector2, selectorN”)
- Selects the combined results of all the specified selectors. -
Next Adjacent Selector (“prev + next”)
- Selects all next elements matching “next” that are immediately preceded by a sibling “prev”. -
Next Siblings Selector (“prev ~ siblings”)
- Selects all sibling elements that follow after the “prev” element, have the same parent, and match the filtering “siblings” selector. -
:not() Selector
- Selects all elements that do not match the given selector. -
:nth-child() Selector
- Selects all elements that are the nth-child of their parent. -
:nth-last-child() Selector
- Selects all elements that are the nth-child of their parent, counting from the last element to the first. -
:nth-last-of-type() Selector
- Selects all elements that are the nth-child of their parent, counting from the last element to the first. -
:nth-of-type() Selector
- Selects all elements that are the nth child of their parent in relation to siblings with the same element name. -
:odd Selector
- Selects odd elements, zero-indexed. See also even. -
:only-child Selector
- Selects all elements that are the only child of their parent. -
:only-of-type Selector
- Selects all elements that have no siblings with the same element name. -
:parent Selector
- Select all elements that have at least one child node (either an element or text). -
:password Selector
- Selects all elements of type password. -
:radio Selector
- Selects all elements of type radio. -
:reset Selector
- Selects all elements of type reset. -
:root Selector
- Selects the element that is the root of the document. -
:selected Selector
- Selects all elements that are selected. -
:submit Selector
- Selects all elements of type submit. -
:target Selector
- Selects the target element indicated by the fragment identifier of the document’s URI. -
:text Selector
- Selects all elements of type text. -
:visible Selector
- Selects all elements that are visible. -
[name!="value"]
- Attribute Not Equal - Select elements that either don't have the specified attribute, or do have the specified attribute but not with a certain value. -
:button
- Selects allbutton
elements and elements of typebutton
. -
:checkbox
- Selects all elements of typecheckbox
. -
:checked
- Matches all elements that are checked or selected. -
:contains()
- Select all elements that contain the specified text. -
:disabled
- Selects all elements that are disabled. -
:empty
- Select all elements that have no children (including text nodes). See also:parent
. -
:enabled
- Selects all elements that are enabled. -
:eq()
- Select the element at indexn
within the matched set. -
:even
- Selects even elements, zero-indexed. See also:odd
. -
:file
- Selects all elements of typefile
. -
:first
- Selects the first matched element. -
:gt()
- Select all elements at an index greater than the givenindex
within the matched set. -
:has()
- Selects elements which contain at least one element that matches the specified selector. -
:header
- Selects all elements that are headers, likeh1
,h2
,h3
and so on. -
:image
- Selects all elements of typeimage
. -
:input
- Selects allinput
,textarea
,select
andbutton
elements. -
:last
- Selects the last matched element. -
:lt()
- Select all elements at an index less than the givenindex
within the matched set. -
:odd
- Selects odd elements, zero-indexed. See also:even
. -
:password
- Selects all elements of typepassword
. -
:parent
- Select all elements that have at least one child node (either an element or text). See:empty
. -
:radio
- Selects all elements of typeradio
. -
:reset
- Selects all elements of typereset
. -
:selected
- Selects all elements that are selected. -
:submit
- Selects all elements of typesubmit
. -
:text
- Selects all elements of typetext
.
-
:present
- Matches all elements that are attached to the DOM. This is a very important property in Selenium page handling, as detached elements cannot be interacted with - they'd throw the infamousStaleElementReferenceException
.
They are only unsupported in the $(selector)
constructor function. They are still available through the .is()
function. That is, $("#x").is(":hidden")
works as expected!
:animated Selector
- Select all elements that are in the progress of an animation at the time the selector is run.-
- Selects element if it is currently focused.:focus
-
- From jQuery UI. Selects elements which can be focused.:focusable
-
- Selects all elements that are hidden.:hidden
-
- From jQuery UI. Selects elements which the user can focus via tabbing.:tabbable
-
- Selects all elements that are visible.:visible
-
- Selects all elements that have no siblings of the given type.:only-of-type