Element

Struct Element 

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

A handle to a DOM element in a browser tab.

Elements are identified by a UUID stored in the extension’s content script. Operations use generic dynamic property access (element[method]()).

§Example

let element = tab.find_element("input[name='email']").await?;

// Set value and submit
element.set_value("user@example.com").await?;
element.type_text("\n").await?; // Press Enter

Implementations§

Source§

impl Element

Source

pub fn id(&self) -> &ElementId

Returns this element’s ID.

Source

pub fn tab_id(&self) -> TabId

Returns the tab ID where this element exists.

Source

pub fn frame_id(&self) -> FrameId

Returns the frame ID where this element exists.

Source§

impl Element

Source

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

Clicks the element.

Uses element.click() internally.

Source

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

Focuses the element.

Source

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

Blurs (unfocuses) the element.

Source

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

Clears the element’s value.

Sets element.value = "".

Source§

impl Element

Source

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

Gets the element’s text content.

Source

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

Gets the element’s inner HTML.

Source

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

Gets the element’s value (for input elements).

Source

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

Sets the element’s value (for input elements).

Source

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

Gets an attribute value.

Returns None if the attribute doesn’t exist.

Source

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

Checks if the element is displayed.

Returns false if offsetParent is null (element is hidden).

Source

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

Checks if the element is enabled.

Returns true if disabled property is false or absent.

Source§

impl Element

Source

pub async fn press(&self, key: Key) -> Result<()>

Presses a navigation/control key.

For typing text, use type_text instead.

§Example
use firefox_webdriver::Key;

element.press(Key::Enter).await?;
element.press(Key::Tab).await?;
element.press(Key::Backspace).await?;
Source

pub async fn type_key( &self, key: &str, code: &str, key_code: u32, printable: bool, ctrl: bool, shift: bool, alt: bool, meta: bool, ) -> Result<()>

Types a single key with optional modifiers (low-level API).

Prefer using press for common keys or type_text for text.

Dispatches full keyboard event sequence: keydown → input → keypress → keyup.

§Arguments
  • key - Key value (e.g., “a”, “Enter”)
  • code - Key code (e.g., “KeyA”, “Enter”)
  • key_code - Legacy keyCode number
  • printable - Whether key produces visible output
  • ctrl - Ctrl modifier
  • shift - Shift modifier
  • alt - Alt modifier
  • meta - Meta modifier
Source

pub async fn type_char(&self, c: char) -> Result<()>

Types a character with default key properties.

Convenience method that uses type_text internally for reliability.

Source

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

Types a text string character by character.

Each character goes through full keyboard event sequence. This is slower but more realistic than set_value.

§Example
element.type_text("Hello, World!").await?;
Source§

impl Element

Source

pub async fn mouse_click(&self, button: u8) -> Result<()>

Clicks the element using mouse events.

Dispatches: mousemove → mousedown → mouseup → click. This is more realistic than click() which uses element.click().

§Arguments
  • button - Mouse button (0=left, 1=middle, 2=right)
Source

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

Double-clicks the element.

Dispatches two click sequences followed by dblclick event.

Source

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

Right-clicks the element (context menu click).

Dispatches contextmenu event.

Source

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

Hovers over the element.

Moves mouse to element center and dispatches mouseenter/mouseover events.

Source

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

Moves mouse to the element center.

Source

pub async fn mouse_down(&self, button: u8) -> Result<()>

Presses mouse button down on the element (without release).

Dispatches only mousedown event. Use with mouse_up() for drag operations.

§Arguments
  • button - Mouse button (0=left, 1=middle, 2=right)
Source

pub async fn mouse_up(&self, button: u8) -> Result<()>

Releases mouse button on the element.

Dispatches only mouseup event. Use with mouse_down() for drag operations.

§Arguments
  • button - Mouse button (0=left, 1=middle, 2=right)
Source§

impl Element

Source

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

Scrolls the element into view.

Uses element.scrollIntoView() with smooth behavior.

Source

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

Scrolls the element into view immediately (no smooth animation).

Source

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

Gets the element’s bounding rectangle.

§Returns

Tuple of (x, y, width, height) in pixels.

Source§

impl Element

Source

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

Checks if the element is checked (for checkboxes/radio buttons).

Source

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

Checks the checkbox/radio button.

Does nothing if already checked.

Source

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

Unchecks the checkbox.

Does nothing if already unchecked.

Source

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

Toggles the checkbox state.

Source

pub async fn set_checked(&self, checked: bool) -> Result<()>

Sets the checked state.

Source§

impl Element

Source

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

Selects an option by visible text (for <select> elements).

§Example
let select = tab.find_element(By::css("select#country")).await?;
select.select_by_text("United States").await?;
Source

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

Selects an option by value attribute (for <select> elements).

Source

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

Selects an option by index (for <select> elements).

Source

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

Gets the selected option’s value (for <select> elements).

Source

pub async fn get_selected_index(&self) -> Result<i64>

Gets the selected option’s index (for <select> elements).

Source

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

Gets the selected option’s text (for <select> elements).

Source

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

Checks if this is a multi-select element.

Source§

impl Element

Source

pub async fn find_element(&self, by: By) -> Result<Element>

Finds a child element using a locator strategy.

§Example
use firefox_webdriver::By;

let form = tab.find_element(By::Id("login-form")).await?;
let btn = form.find_element(By::Css("button[type='submit']")).await?;
Source

pub async fn find_elements(&self, by: By) -> Result<Vec<Element>>

Finds all child elements using a locator strategy.

§Example
use firefox_webdriver::By;

let form = tab.find_element(By::Id("login-form")).await?;
let inputs = form.find_elements(By::Tag("input")).await?;
Source§

impl Element

Source

pub async fn get_property(&self, name: &str) -> Result<Value>

Gets a property value via element[name].

§Arguments
  • name - Property name (e.g., “value”, “textContent”)
Source

pub async fn set_property(&self, name: &str, value: Value) -> Result<()>

Sets a property value via element[name] = value.

§Arguments
  • name - Property name
  • value - Value to set
Source

pub async fn call_method(&self, name: &str, args: Vec<Value>) -> Result<Value>

Calls a method via element[name](...args).

§Arguments
  • name - Method name
  • args - Method arguments
Source§

impl Element

Source

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

Captures a PNG screenshot of this element.

Returns base64-encoded image data.

§Example
let element = tab.find_element("#chart").await?;
let screenshot = element.screenshot().await?;
Source

pub async fn screenshot_jpeg(&self, quality: u8) -> Result<String>

Captures a JPEG screenshot of this element with specified quality.

§Arguments
  • quality - JPEG quality (0-100)
Source

pub async fn screenshot_bytes(&self) -> Result<Vec<u8>>

Captures a screenshot and returns raw bytes.

Source

pub async fn save_screenshot(&self, path: impl AsRef<Path>) -> Result<()>

Captures a screenshot and saves to a file.

Format is determined by file extension (.png or .jpg/.jpeg).

Trait Implementations§

Source§

impl Clone for Element

Source§

fn clone(&self) -> Element

Returns a duplicate 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

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> Same for T

Source§

type Output = T

Should always be Self
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<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