Skip to content

Commit f2003d4

Browse files
authored
Docs: Correctly describe behavior when query's parameter is a string (#659)
1 parent 7c9c5cb commit f2003d4

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

CHANGELOG.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ A release with an intentional breaking changes is marked with:
3030
** {issue}647[#647]: Fix logic bug in `intersects?`. Added tests to test suite. ({person}dgr[@dgr])
3131
** {issue}649[#649]: When supplied a vector argument for `q-text`, `fill-multi` and `fill-human-multi` now fill fields in the order that fields appear in the vector. Previously, the order was not guaranteed. ({person}dgr[@dgr])
3232
** {issue}657[#657]: Make `set-<xyz>-timeout` functions resilient to reasonable non-integer timeouts (e.g., rationals, doubles, etc.). ({person}dgr[@dgr])
33+
* Docs
34+
** {issue}656[#656]: Correctly describe behavior when query's parameter is a string. The User Guide and `query` doc strings say that a string passed to `query` is interpreted as an XPath expression. In fact, `query` interprets this as either XPath or CSS depending on the setting of the driver's `:locator` parameter, which can be changed. ({person}dgr[@dgr])
3335

3436
== v1.1.41 [minor breaking] - 2024-08-14 [[v1.1.41]]
3537

doc/01-user-guide.adoc

+13-1
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,10 @@ If you want to query for an element with an ID of "active", use the map syntax,
531531
(e/fill driver {:id "uname"} "Etaoin Again" k/enter)
532532
----
533533

534-
* a string containing an link:{xpath-sel}[XPath] expression.
534+
* a string containing either an link:{xpath-sel}[XPath] or a link:{css-sel}[CSS] expression.
535+
The way `query` interprets this string depends on the driver's `:locator` setting.
536+
By default, the driver's `:locator` is set to `"xpath"`.
537+
The `:locator` can be changed using the `use-css`, `with-css`, `use-xpath`, and `with-xpath` functions and macros.
535538
(Be careful when writing XPath manually; see <<troubleshooting>>.)
536539
Here, we find an `input` tag with an attribute `id` of `uname` and an attribute `name` of `username`:
537540
+
@@ -543,6 +546,15 @@ Here, we find an `input` tag with an attribute `id` of `uname` and an attribute
543546
;; let's check if that worked as expected:
544547
(e/get-element-value driver :uname)
545548
;; => "XPath can be tricky"
549+
550+
;; let's modify the driver to use CSS rather than XPath
551+
;; note that this returns a new, modified copy of the driver
552+
;; the old driver is still valid, however
553+
(def driver-css (e/use-css driver))
554+
(e/refresh driver-css)
555+
(e/fill driver-css "input#uname[name='username']" "CSS can be tricky, too")
556+
(e/get-element-value driver-css :uname)
557+
;; => "CSS can be tricky, too"
546558
----
547559

548560
* a map with either `:xpath` or `:css` key with a string in corresponding syntax:

src/etaoin/api.clj

+16-9
Original file line numberDiff line numberDiff line change
@@ -602,25 +602,32 @@
602602
- Note that `:active` conflicts with this usage and therefore you
603603
cannot search for a keyword named `:active` and expect to find an element
604604
with ID equal to \"active\". In this case, use `{:id \"active\"}`.
605-
- an XPath expression:
606-
- `\".//input[@id='uname']\"`
605+
- a string that contains either an XPath or CSS expression, depending on the
606+
driver's locator setting. Defaults to XPath.
607+
See [[use-css]], [[with-css]], [[use-xpath]], [[with-xpath]] for methods
608+
changing the driver's locator setting.
609+
- XPath: `\".//input[@id='uname'][@name='username']\"`
610+
- CSS: `\"input#uname[name='username']\"`
607611
- a map with either `:xpath` or `:css`:
608612
- `{:xpath \".//input[@id='uname']\"`}`
609613
- `{:css \"input#uname[name='username']\"}`
610614
- any other map is converted to an XPath expression:
611615
- `{:tag :div}`
612616
- is equivalent to XPath: `\".//div\"`
613-
- multiple of the above (wrapped in a vector or not).
614-
The result of each expression is fed into the next.
615-
- `{:tag :div} \".//input[@id='uname']\"`
616-
- `[{:tag :div} \".//input[@id='uname']\"]`
617+
- multiple of the above (wrapped in a vector or not).
618+
The result of each search anchors the search for the next,
619+
effectively providing a path through the DOM (though you do not
620+
have to specify each and every point in the path).
621+
- `{:tag :div} \".//input[@id='uname']\"`
622+
- `[{:tag :div} \".//input[@id='uname']\"]`
623+
Returns the final element's unique identifier, or throws if any element
624+
is not found.
617625
618-
Returns the found element's unique identifier, or throws when not found.
619-
620-
See [Selecting Elements](/doc/01-user-guide.adoc#querying) for more details.
626+
See [Selecting Elements](/doc/01-user-guide.adoc#querying) for more details.
621627
622628
Makes use of:
623629
- https://www.w3.org/TR/webdriver2/#dfn-get-active-element
630+
- https://www.w3.org/TR/webdriver2/#dfn-find-element
624631
- https://www.w3.org/TR/webdriver2/#dfn-find-element-from-element"
625632
([driver q]
626633
(cond

0 commit comments

Comments
 (0)