Skip to main content

TestElement

Struct TestElement 

Source
pub struct TestElement { /* private fields */ }
Expand description

A wrapped WebElement.

Implementations§

Source§

impl TestElement

Source

pub fn element(&self) -> &WebElement

The WebDriver element underneath, for what this wrapper has no method for.

Source

pub async fn click(&self) -> Result<()>

Click the element.

Source

pub async fn extend_click(&self) -> Result<()>

Press the element with control held, which is how a selection is commonly extended by one item.

Source

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.

Source

pub async fn hover(&self) -> Result<()>

Rest the pointer on the element without pressing anything.

Source

pub async fn double_click(&self) -> Result<()>

Press the element twice, as one gesture.

Source

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.

Source

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.

Source

pub async fn context_click(&self) -> Result<()>

Right-click the element.

Source

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.

Source

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.

Source

pub async fn alt_drag_by(&self, dx: i64, dy: i64) -> Result<()>

The same with alt held.

Source

pub async fn text(&self) -> Result<String>

Get the text contents for this element.

Source

pub async fn prop(&self, name: &str) -> Result<String>

One of the element’s DOM properties.

Source

pub async fn attr(&self, name: &str) -> Result<String>

One of the element’s DOM attributes, or the empty string when it has none.

Source

pub async fn scroll_into_view(&self) -> Result<()>

Bring the element into view.

Source

pub async fn focus(&self) -> Result<()>

Put keyboard focus here without pressing anything.

Source

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.

Source

pub async fn rect(&self) -> Result<ElementRect>

Where this element is on screen, and how big it is.

Source

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.

Source

pub async fn value(&self) -> Result<String>

The element’s value property.

Source

pub async fn clear(&self) -> Result<()>

Clear the element contents.

Source

pub async fn send_keys(&self, keys: &str) -> Result<()>

Send the specified input targeting the element.

Source

pub async fn pressed(&self) -> Result<bool>

Whether the element is currently pressed, by aria-pressed.

Source

pub async fn enabled(&self) -> Result<bool>

Whether the control can be worked at all.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub async fn find_all_texts(&self, by: impl IntoBy) -> Result<Vec<String>>

Find the text contents of all nodes match the given By.

Source

pub async fn find_one_by_xpath(&self, xpath: &str) -> Result<TestElement>

Find an element by xpath.

Source

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.

Source

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.

Source

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.

Source

pub async fn find_all(&self, by: impl IntoBy) -> Result<Vec<TestElement>>

Find all elements matching by.

Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more