fantoccini::elements

Struct Element

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

A single DOM element on the current page.

Note that there is a lot of subtlety in how you can interact with an element through WebDriver, which the WebDriver standard goes into detail on. The same goes for inspecting element state.

Implementations§

Source§

impl Element

Source

pub fn from_element_id(client: Client, element_id: ElementRef) -> Self

Construct an Element with the specified element id. The element id is the id given by the webdriver.

Source

pub fn client(self) -> Client

Get back the Client hosting this Element.

Source

pub fn element_id(&self) -> ElementRef

Get the element id as given by the webdriver.

Source§

impl Element

Source

pub async fn enter_frame(&self) -> Result<(), CmdError>

Switches to the frame contained within the element.

See 10.5 Switch To Frame of the WebDriver standard.

Source§

impl Element

Source

pub async fn find(&self, search: Locator<'_>) -> Result<Element, CmdError>

Find the first descendant element that matches the given Locator.

See 12.4 Find Element From Element of the WebDriver standard.

Source

pub async fn find_all( &self, search: Locator<'_>, ) -> Result<Vec<Element>, CmdError>

Find all descendant elements that match the given Locator.

See 12.5 Find Elemente From Element of the WebDriver standard.

Source§

impl Element

Source

pub async fn is_selected(&self) -> Result<bool, CmdError>

Return true if the element is currently selected.

See 13.1 Is Element Selected of the WebDriver standard.

Source

pub async fn is_enabled(&self) -> Result<bool, CmdError>

Return true if the element is currently enabled.

See 13.8 Is Element Enabled of the WebDriver standard.

Source

pub async fn is_displayed(&self) -> Result<bool, CmdError>

Return true if the element is currently displayed.

See Element Displayedness of the WebDriver standard.

Source

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

Look up an attribute value for this element by name.

Ok(None) is returned if the element does not have the given attribute.

See 13.2 Get Element Attribute of the WebDriver standard.

Source

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

Look up a DOM property for this element by name.

Ok(None) is returned if the element does not have the given property.

Boolean properties such as “checked” will be returned as the String “true” or “false”.

See 13.3 Get Element Property of the WebDriver standard.

Source

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

Look up the computed value of a CSS property for this element by name.

Ok(String::new()) is returned if the the given CSS property is not found.

See 13.4 Get Element CSS Value of the WebDriver standard.

Source

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

Retrieve the text contents of this element.

See 13.5 Get Element Text of the WebDriver standard.

Source

pub async fn tag_name(&self) -> Result<String, CmdError>

Retrieve the tag name of this element.

See 13.6 Get Element Tag Name of the WebDriver standard.

Source

pub async fn rectangle(&self) -> Result<(f64, f64, f64, f64), CmdError>

Gets the x, y, width, and height properties of the current element.

See 13.7 Get Element Rect of the WebDriver standard.

Source

pub async fn html(&self, inner: bool) -> Result<String, CmdError>

Retrieve the HTML contents of this element.

inner dictates whether the wrapping node’s HTML is excluded or not. For example, take the HTML:

<div id="foo"><hr /></div>

With inner = true, <hr /> would be returned. With inner = false, <div id="foo"><hr /></div> would be returned instead.

Source§

impl Element

Source

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

Simulate the user clicking on this element.

See 14.1 Element Click of the WebDriver standard.

Source

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

Clear this element.

See 14.2 Element Clear of the WebDriver standard.

Source

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

Simulate the user sending keys to this element.

This operation scrolls into view the form control element and then sends the provided keys to the element. In case the element is not keyboard-interactable, an element not interactable error is returned.

See 14.3 Element Send Keys of the WebDriver standard.

Source§

impl Element

Source

pub async fn screenshot(&self) -> Result<Vec<u8>, CmdError>

Get a PNG-encoded screenshot of this element.

See 19.2 Take Element Screenshot of the WebDriver standard.

Source§

impl Element

Higher-level operations.

Source

pub async fn follow(&self) -> Result<(), CmdError>

Follow the href target of the element matching the given CSS selector without causing a click interaction.

Source

pub async fn select_by(&self, locator: Locator<'_>) -> Result<(), CmdError>

Find and click an <option> child element by a locator.

This method clicks the first <option> element that is found. If the element wasn’t found, CmdError::NoSuchElement will be issued.

Source

pub async fn select_by_value(&self, value: &str) -> Result<(), CmdError>

Find and click an option child element by its value attribute.

Source

pub async fn select_by_index(&self, index: usize) -> Result<(), CmdError>

Find and click an <option> child element by its index.

This method clicks the first <option> element that is an indexth child (option:nth-of-type(index+1)). This will be the indexth <option> element if the current element is a <select>. If you use this method on an Element that is not a <select> (such as on a full <form>), it may not do what you expect if there are multiple <select> elements in the form, or if it there are stray <option> in the form.

The indexing in this method is 0-based.

Source

pub async fn select_by_label(&self, label: &str) -> Result<(), CmdError>

Find and click an <option> element by its visible text.

The method doesn’t make any escaping for the argument like it is done in python webdriver client for example. It also doesn’t make any normalizations before match.

Trait Implementations§

Source§

impl Clone for Element

Source§

fn clone(&self) -> Element

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Element

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for Element

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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