-
Notifications
You must be signed in to change notification settings - Fork 93
Element API
Once you've positioned your browser driver at the page you want and have setup any other parameters (like [caching](Caching Support), [grid support](Grid Support), or a special [Firefox profile](Firefox Support)), you are ready to interact with individual elements on the page.
The heart of clj-webdriver's API is the find-it
function. This function wraps the various ways that Selenium-WebDriver allows you to find elements and condenses them into a handful of "mini languages" for finding elements on the page, hopefully in a more Clojure-amenable fashion. Since this is the initial way people start playing with this API, I will continue to maintain the most up-to-date information about it on the README:
Once you've used find-it
to locate an element of interest, you can perform any number of actions on the element:
Element Information:
-
attribute
- Return the given attribute of the given page element -
value
- A shortcut for(attribute element :value)
-
tag-name
- Return the tag of the given element -
exists?
- Given a find-it-style form query, return true or false depending on whether or not the given element exists (this is the only function that takes a query, instead of an element object, the reasoning for which is included in this Google group thread) -
displayed?
,visible?
,present?
- Synonyms for the same function, which returns true or false depending on whether or not the given element is visible on the page -
text
- Return the textual content of the given page element -
html
- Return the outer HTML of the given page element -
xpath
- Return the XPath expression which points to the given page element -
location
- Return the X/Y coordinates of the given page element within the view port -
location-once-visible
- Return the same aslocation
, but only when the given element is made visible by scrolling down the page
Here are information-based functions that are specific to form elements:
-
selected?
- Return true or false depending on whether or not the given element is selected -
enabled?
- Return true or false depending on whether or not the given element is enabled
Element Actions:
(Many of these functions are limited specifically to form elements)
-
click
- Click the given page element -
flash
- Visibly flash the given element (helpful for spotting hard-to-see elements on the page during test composition) -
focus
- Shift focus to the given page element -
submit
- Submit the form that contains the given page element -
clear
- Clear the contents of the given element (e.g. text field) -
select
- Select the given option element -
deselect
- Deselect the given option element (multi-select select field) -
send-keys
,input-text
- Send the given string to the given page element (e.g. text field) -
drag-and-drop-by
- Drag an element by given horizontal and vertical pixel dimensions -
drag-and-drop-on
- Drag one element onto another
Read the page on Caching Support for more information about caching elements of the page.
The clj-webdriver Uncyclo by Daniel Gregoire and community is licensed under a Creative Commons Attribution 4.0 International License. Based on a work at https://github.com/semperos/clj-webdriver/wiki.