chromiumoxide::element

Struct Element

Source
pub struct Element {
    pub remote_object_id: RemoteObjectId,
    pub backend_node_id: BackendNodeId,
    pub node_id: NodeId,
    /* private fields */
}
Expand description

Represents a DOM Element.

Fields§

§remote_object_id: RemoteObjectId

The Unique object identifier

§backend_node_id: BackendNodeId

Identifier of the backend node.

§node_id: NodeId

The identifier of the node this element represents.

Implementations§

Source§

impl Element

Source

pub async fn find_element(&self, selector: impl Into<String>) -> Result<Self>

Returns the first element in the document which matches the given CSS selector.

Source

pub async fn find_elements( &self, selector: impl Into<String>, ) -> Result<Vec<Element>>

Return all Elements in the document that match the given selector

Source

pub async fn bounding_box(&self) -> Result<BoundingBox>

Returns the bounding box of the element (relative to the main frame)

Source

pub async fn clickable_point(&self) -> Result<Point>

Returns the best Point of this node to execute a click on.

Source

pub async fn call_js_fn( &self, function_declaration: impl Into<String>, await_promise: bool, ) -> Result<CallFunctionOnReturns>

Submits a javascript function to the page and returns the evaluated result

§Example get the element as JSON object
    let js_fn = "function() { return this; }";
    let element_json = element.call_js_fn(js_fn, false).await?;
§Execute an async javascript function
    let js_fn = "async function() { return this; }";
    let element_json = element.call_js_fn(js_fn, true).await?;
Source

pub async fn json_value(&self) -> Result<Value>

Returns a JSON representation of this element.

Source

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

Calls focus on the element.

Source

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

Scrolls the element into view and uses a mouse event to move the mouse over the center of this element.

Source

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

Scrolls the element into view.

Fails if the element’s node is not a HTML element or is detached from the document

Source

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

This focuses the element by click on it

Bear in mind that if click() triggers a navigation this element may be not exist anymore.

Source

pub async fn type_str(&self, input: impl AsRef<str>) -> Result<&Self>

Type the input

§Example type text into an input element
    let element = page.find_element("input#searchInput").await?;
    element.click().await?.type_str("this goes into the input field").await?;
Source

pub async fn press_key(&self, key: impl AsRef<str>) -> Result<&Self>

Presses the key.

§Example type text into an input element and hit enter
    let element = page.find_element("input#searchInput").await?;
    element.click().await?.type_str("this goes into the input field").await?
         .press_key("Enter").await?;
Source

pub async fn description(&self) -> Result<Node>

The description of the element’s node

Source

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

Attributes of the Element node in the form of flat array `[name1, value1, name2, value2]

Source

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

Returns the value of the element’s attribute

Source

pub async fn iter_attributes( &self, ) -> Result<impl Stream<Item = (String, Result<Option<String>>)> + '_>

A Stream over all attributes and their values

Source

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

The inner text of this element.

Source

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

The inner HTML of this element.

Source

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

The outer HTML of this element.

Source

pub async fn string_property( &self, property: impl AsRef<str>, ) -> Result<Option<String>>

Returns the string property of the element.

If the property is an empty String, None is returned.

Source

pub async fn property(&self, property: impl AsRef<str>) -> Result<Option<Value>>

Returns the javascript property of this element where property is the name of the requested property of this element.

See also Element::inner_html.

Source

pub async fn properties(&self) -> Result<HashMap<String, PropertyDescriptor>>

Returns a map with all PropertyDescriptors of this element keyed by their names

Source

pub async fn screenshot( &self, format: CaptureScreenshotFormat, ) -> Result<Vec<u8>>

Scrolls the element into and takes a screenshot of it

Source

pub async fn save_screenshot( &self, format: CaptureScreenshotFormat, output: impl AsRef<Path>, ) -> Result<Vec<u8>>

Save a screenshot of the element and write it to output

Trait Implementations§

Source§

impl Debug for Element

Source§

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

Formats the value using the given formatter. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T