pub struct TestElement { /* private fields */ }Expand description
A wrapped WebElement.
Implementations§
Source§impl TestElement
impl TestElement
Sourcepub fn element(&self) -> &WebElement
pub fn element(&self) -> &WebElement
The WebDriver element underneath, for what this wrapper has no method for.
Sourcepub async fn extend_click(&self) -> Result<()>
pub async fn extend_click(&self) -> Result<()>
Press the element with control held, which is how a selection is commonly extended by one item.
Sourcepub async fn shift_click(&self) -> Result<()>
pub async fn shift_click(&self) -> Result<()>
Press the element with shift held, which picks the run from the last item picked to this one in a list that has an order.
Sourcepub async fn hover(&self) -> Result<()>
pub async fn hover(&self) -> Result<()>
Rest the pointer on the element without pressing anything.
Sourcepub async fn double_click(&self) -> Result<()>
pub async fn double_click(&self) -> Result<()>
Press the element twice, as one gesture.
Sourcepub async fn double_click_by(&self, dx: i64, dy: i64) -> Result<()>
pub async fn double_click_by(&self, dx: i64, dy: i64) -> Result<()>
The same, a given offset from the element’s centre, for one element covering a whole surface, where on it a gesture lands being what the gesture is about.
Sourcepub async fn click_by(&self, dx: i64, dy: i64) -> Result<()>
pub async fn click_by(&self, dx: i64, dy: i64) -> Result<()>
Press the element once, a given offset from its centre. A slider is one element covering its whole travel, so where on it a press lands is the whole of what the press says.
Sourcepub async fn context_click(&self) -> Result<()>
pub async fn context_click(&self) -> Result<()>
Right-click the element.
Sourcepub async fn drag_by(&self, dx: i64, dy: i64) -> Result<()>
pub async fn drag_by(&self, dx: i64, dy: i64) -> Result<()>
Press on this element and drag dx, dy from where it is, leaving
the button down.
The pointer first steps up to 8px towards the offset, so the page sees
a drag begin, and then moves the rest of the way: it comes to rest
exactly dx, dy from where it was pressed.
Sourcepub async fn drag_from_by(
&self,
at_x: i64,
at_y: i64,
dx: i64,
dy: i64,
) -> Result<()>
pub async fn drag_from_by( &self, at_x: i64, at_y: i64, dx: i64, dy: i64, ) -> Result<()>
The same begun at a point of the element’s own choosing rather than at
its centre, at_x and at_y being pixels from that centre.
A sweep that has to begin in one row of a grid cannot begin wherever the element happens to be halved.
Sourcepub async fn attr(&self, name: &str) -> Result<String>
pub async fn attr(&self, name: &str) -> Result<String>
One of the element’s DOM attributes, or the empty string when it has none.
Sourcepub async fn scroll_into_view(&self) -> Result<()>
pub async fn scroll_into_view(&self) -> Result<()>
Bring the element into view.
Sourcepub async fn visible(&self) -> Result<bool>
pub async fn visible(&self) -> Result<bool>
Whether the element is displayed, as WebDriver judges it: present in
the page is not enough, it must also not be hidden by CSS
(display: none, visibility: hidden) or have no size.
Answers once, at the time of asking; it does not wait.
Sourcepub async fn rect(&self) -> Result<ElementRect>
pub async fn rect(&self) -> Result<ElementRect>
Where this element is on screen, and how big it is.
Sourcepub async fn css(&self, name: &str) -> Result<String>
pub async fn css(&self, name: &str) -> Result<String>
One of the element’s computed CSS properties, as getComputedStyle
serializes it.
The value is read in the page rather than through WebDriver’s own
command, which chromedriver answers with every colour rewritten as
rgba(...): a colour reads rgb(255, 0, 0) in every engine alike.
Sourcepub async fn send_keys(&self, keys: &str) -> Result<()>
pub async fn send_keys(&self, keys: &str) -> Result<()>
Send the specified input targeting the element.
Sourcepub async fn pressed(&self) -> Result<bool>
pub async fn pressed(&self) -> Result<bool>
Whether the element is currently pressed, by aria-pressed.
Sourcepub async fn disabled(&self) -> Result<bool>
pub async fn disabled(&self) -> Result<bool>
Whether the control says it is out of play, by aria-disabled. This is
the question to ask of a custom control: enabled reads the form
control’s disabled, which an element that is not a form control
cannot carry, so it answers true for one however dead it is.
Sourcepub async fn wait_until(
&self,
what: impl Display,
condition: impl AsyncFnMut() -> Result<bool>,
) -> Result<()>
pub async fn wait_until( &self, what: impl Display, condition: impl AsyncFnMut() -> Result<bool>, ) -> Result<()>
Repeat condition until it holds, or the wait timeout passes.
Sourcepub async fn wait_until_within(
&self,
timeout: Duration,
what: impl Display,
condition: impl AsyncFnMut() -> Result<bool>,
) -> Result<()>
pub async fn wait_until_within( &self, timeout: Duration, what: impl Display, condition: impl AsyncFnMut() -> Result<bool>, ) -> Result<()>
Self::wait_until where the default deadline is the wrong one,
because what is being waited for has a length of its own that is
known and is close to it. A wait that habitually lands just inside
its cap is not passing, it is winning a race.
Every lookup condition makes is bounded by what is left of
timeout, so a slow one cannot carry the wait past it.
Sourcepub async fn wait_texts<const N: usize>(
&self,
by: impl IntoBy,
expected: [&str; N],
) -> Result<()>
pub async fn wait_texts<const N: usize>( &self, by: impl IntoBy, expected: [&str; N], ) -> Result<()>
Wait until the text of every node matching by reads expected.
Sourcepub async fn wait_count(&self, by: impl IntoBy, expected: usize) -> Result<()>
pub async fn wait_count(&self, by: impl IntoBy, expected: usize) -> Result<()>
Wait until exactly expected nodes match by.
Exact equality, polled, starting immediately – which is a trap
directly after an action. A call whose expected is the count that
was already on screen is answered by the very first poll, before the
action it is meant to be checking can have landed, so it asserts only
that the page has not caught up yet. It stays green for months and
then turns into a hard timeout the first time anything, however
unrelated, makes the page a few milliseconds slower to lay out –
and blames that change. Where the count is supposed to have changed,
read it before the action and say so with Self::wait_count_from,
which refuses the degenerate case instead of passing it. Plain
wait_count belongs where a count is being established rather than
changed: a page just loaded, a selector first asserted.
Sourcepub async fn count(&self, by: impl IntoBy) -> Result<usize>
pub async fn count(&self, by: impl IntoBy) -> Result<usize>
How many nodes match by right now, without waiting for any
particular number of them. The before-read Self::wait_count_from
asks for.
Sourcepub async fn wait_count_from(
&self,
by: impl IntoBy,
before: usize,
expected: usize,
) -> Result<()>
pub async fn wait_count_from( &self, by: impl IntoBy, before: usize, expected: usize, ) -> Result<()>
Wait until exactly expected nodes match by, having been told the
before count that the action in between was supposed to change.
The before-read is the whole point. Self::wait_count cannot
tell “the action landed” apart from “the action has not started”,
because both of those look exactly like the number it was given; this
can, because it knows which number meant “not yet”. When before
already equals expected it refuses outright rather than passing on
the first poll, so the assertion that verifies nothing fails loudly
the day it is written instead of years later on somebody else’s
change. Take before with Self::count immediately before the
action – at the top of the test it is a different question, and
anything landing in between makes it a lie.
Sourcepub async fn find_all_texts(&self, by: impl IntoBy) -> Result<Vec<String>>
pub async fn find_all_texts(&self, by: impl IntoBy) -> Result<Vec<String>>
Find the text contents of all nodes match the given By.
Sourcepub async fn find_one_by_xpath(&self, xpath: &str) -> Result<TestElement>
pub async fn find_one_by_xpath(&self, xpath: &str) -> Result<TestElement>
Find an element by xpath.
Sourcepub async fn find_one_by(&self, by: impl IntoBy) -> Result<TestElement>
pub async fn find_one_by(&self, by: impl IntoBy) -> Result<TestElement>
Find the one element matching by, waiting for it to appear.
Refusing a second match is the point. A selector that was meant
to name one thing and now names three is the way a guard goes quiet,
so this says so instead of picking. Where several is what the page
is, the question was never “the one”: see Self::find_nth.
Sourcepub async fn find_nth(
&self,
by: impl IntoBy,
index: usize,
) -> Result<TestElement>
pub async fn find_nth( &self, by: impl IntoBy, index: usize, ) -> Result<TestElement>
Find the indexth element matching by, waiting for that many to
appear.
What a test asks when several is the answer, and the reading twin
of TestDriver::press_nth: the row a test appended is the one at
the end, three related buttons are three whatever is measured, and
neither is a broken selector for Self::find_one_by to refuse.
Asked here rather than by reaching for Self::find_all and
indexing the answer, which drops the wait along with the sentence
saying which one was wanted.
A wait polling for an element to arrive still wants
Self::find_all: nothing there is an answer to that question, and
this has a deadline of its own to spend before it says so.
Sourcepub async fn find_first(&self, by: impl IntoBy) -> Result<TestElement>
pub async fn find_first(&self, by: impl IntoBy) -> Result<TestElement>
The first element matching by, however many there turn out to be.
Self::find_nth says when that is the question.
Sourcepub async fn find_all(&self, by: impl IntoBy) -> Result<Vec<TestElement>>
pub async fn find_all(&self, by: impl IntoBy) -> Result<Vec<TestElement>>
Find all elements matching by.
Sourcepub async fn find_all_within(
&self,
timeout: Duration,
by: impl IntoBy,
) -> Result<Vec<TestElement>>
pub async fn find_all_within( &self, timeout: Duration, by: impl IntoBy, ) -> Result<Vec<TestElement>>
Self::find_all with a bound of the caller’s choosing on the call
itself, for putting the question to a browser which is still
starting. Inside a wait, the bound is never longer than what is left
of that wait. See
TestDriver::load_timeout.