Skip to content

Commit

Permalink
Add find-element(s)-from-element (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
hendursaga authored Sep 23, 2024
1 parent d871d65 commit 3c2c377
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@

#:find-element
#:find-elements
#:find-element-from-element
#:find-elements-from-element
#:active-element
#:element-clear
#:element-click
Expand Down
26 changes: 26 additions & 0 deletions src/webdriver.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,32 @@ See https://www.w3.org/TR/webdriver1/#find-elements ."
collect (make-instance 'element :id id)))
(protocol-error (err) (handle-find-error err :value value :by by))))

(defun find-element-from-element (element-id value &key (by :css-selector) (session *session*))
"Find an element that matches VALUE using location strategy in BY with a start node of ELEMENT-ID.
Category: Elements
See FIND-ELEMENT.
See https://www.w3.org/TR/webdriver1/#find-element-from-element ."
(handler-case
(let ((response (http-post (session-path session "/element/~a/element" element-id)
:value value :using (by by))))
(make-instance 'element
:id (cdadr (assoc :value response))))
(protocol-error (err) (handle-find-error err :value value :by by))))

(defun find-elements-from-element (element-id value &key (by :css-selector) (session *session*))
"Find elements that match VALUE using location strategy in BY with a start node of ELEMENT-ID.
Category: Elements
See FIND-ELEMENTS.
See https://www.w3.org/TR/webdriver1/#find-elements-from-element ."
(handler-case
(let ((response (http-post (session-path session "/element/~a/elements" element-id)
:value value :using (by by))))
(loop for ((nil . id)) in (cdr (assoc :value response))
collect (make-instance 'element :id id)))
(protocol-error (err) (handle-find-error err :value value :by by))))

(deftype element-location-strategy ()
"An element location strategy is an enumerated attribute deciding what technique should be used to search for elements in the current browsing context.
See: https://www.w3.org/TR/webdriver1/#dfn-strategy ."
Expand Down

0 comments on commit 3c2c377

Please sign in to comment.