wallaby v0.21.0 Wallaby.Query View Source
Provides the query DSL.
Queries are used to locate and retrieve DOM elements from a browser (see
Wallaby.Browser
). You create queries like so:
Query.css(".some-css")
Query.xpath(".//input")
Form elements
There are several custom finders for locating form elements. Each of these allows finding by their name, id text, or label text. This allows for more robust querying and decouples the query from presentation selectors like css classes.
Query.text_field("My Name")
Query.checkbox("Checkbox")
Query.select("A Fancy Select Box")
Query Options
All of the query operations accept the following options:
:count
- The number of elements that should be found (default: 1).:visible
- Determines if the query should return only visible elements (default: true).:text
- Text that should be found inside the element (default: nil).:at
- The position number of the element to select if multiple elements satisfy the selection criteria. (:all for all elements)
Re-using queries
It is often convenient to re-use queries. The easiest way is to use module attributes:
@name_field Query.text_field("User Name")
@submit_button Query.button("Save")
If the queries need to be dynamic then you should create a module that encapsulates the queries as functions:
defmodule TodoListPage do
def todo_list do
Query.css(".todo-list")
end
def todos(count) do
Query.css(".todo", count: count)
end
end
What does my query do?
Wanna check out what exactly your query will do? Look no further than
Wallaby.Query.compile/1
- it takes a query and returns the css or xpath
query that will be sent to the driver:
iex> Wallaby.Query.compile Wallaby.Query.text("my text")
{:xpath, ".//*[contains(normalize-space(text()), \"my text\")]"}
So, whenever you’re not sure whatever a specific query will do just compile it to get all the details!
Link to this section Summary
Functions
Checks if the provided attribute, value pair is contained anywhere
Looks for a button (literal button or input type button, submit, image or reset) where the provided selector is the id, name, value, alt or title of the button
Looks for a checkbox where the provided selector is the id, name or placeholder of the checkbox itself or alternatively the id or the text of the label
Compiles a query into css or xpath so its ready to be sent to the driver
Literally queries for the css selector you provide
Looks for a file input where the selector is the id or name of the file input itself or the id or text of the label
Looks for a text input field where the provided selector is the id, name or placeholder of the text field itself or alternatively the id or the text of the label
Looks for a link where the selector is the id, link text, title of the link itself or the alt of an image child node
Looks for an option that contains the given text
Looks for a radio button where the provided selector is the id, name or placeholder of the radio button itself or alternatively the id or the text of the label
Looks for a select box where the provided selector is the id or name of the select box itself or alternatively the id or the text of the label
Checks if the provided text is contained anywhere
Checks if the provided value is contained anywhere
Literally queries for the xpath selector you provide
Link to this section Types
conditions() :: [count: non_neg_integer(), text: String.t(), visible: boolean(), minimum: non_neg_integer(), at: pos_integer()]
html_validation() :: :bad_label | :button_type | nil
method() :: :css | :xpath | :link | :button | :fillable_field | :checkbox | :radio_button | :option | :select | :file_field
t() :: %Wallaby.Query{conditions: conditions(), html_validation: html_validation(), method: method(), result: result(), selector: selector()}
Link to this section Functions
Checks if the provided attribute, value pair is contained anywhere.
Looks for a button (literal button or input type button, submit, image or reset) where the provided selector is the id, name, value, alt or title of the button.
Looks for a checkbox where the provided selector is the id, name or placeholder of the checkbox itself or alternatively the id or the text of the label.
Compiles a query into css or xpath so its ready to be sent to the driver
iex> Wallaby.Query.compile Wallaby.Query.text("my text")
{:xpath, ".//*[contains(normalize-space(text()), \"my text\")]"}
iex> Wallaby.Query.compile Wallaby.Query.css("#some-id")
{:css, "#some-id"}
Literally queries for the css selector you provide.
Looks for a file input where the selector is the id or name of the file input itself or the id or text of the label.
Looks for a text input field where the provided selector is the id, name or placeholder of the text field itself or alternatively the id or the text of the label.
Looks for a link where the selector is the id, link text, title of the link itself or the alt of an image child node.
Looks for an option that contains the given text.
Looks for a radio button where the provided selector is the id, name or placeholder of the radio button itself or alternatively the id or the text of the label.
Looks for a select box where the provided selector is the id or name of the select box itself or alternatively the id or the text of the label.
Checks if the provided text is contained anywhere.
Checks if the provided value is contained anywhere.
Literally queries for the xpath selector you provide.