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 EnterImplementations§
Source§impl Element
impl Element
Sourcepub async fn get_inner_html(&self) -> Result<String>
pub async fn get_inner_html(&self) -> Result<String>
Gets the element’s inner HTML.
Sourcepub async fn set_value(&self, value: &str) -> Result<()>
pub async fn set_value(&self, value: &str) -> Result<()>
Sets the element’s value (for input elements).
Sourcepub async fn get_attribute(&self, name: &str) -> Result<Option<String>>
pub async fn get_attribute(&self, name: &str) -> Result<Option<String>>
Gets an attribute value.
Returns None if the attribute doesn’t exist.
Sourcepub async fn is_displayed(&self) -> Result<bool>
pub async fn is_displayed(&self) -> Result<bool>
Checks if the element is displayed.
Returns false if offsetParent is null (element is hidden).
Sourcepub async fn is_enabled(&self) -> Result<bool>
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
impl Element
Sourcepub async fn type_key(
&self,
key: &str,
code: &str,
key_code: u32,
printable: bool,
ctrl: bool,
shift: bool,
alt: bool,
meta: bool,
) -> Result<()>
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 numberprintable- Whether key produces visible outputctrl- Ctrl modifiershift- Shift modifieralt- Alt modifiermeta- Meta modifier
Source§impl Element
impl Element
Sourcepub async fn mouse_click(&self, button: u8) -> Result<()>
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)
Sourcepub async fn double_click(&self) -> Result<()>
pub async fn double_click(&self) -> Result<()>
Double-clicks the element.
Dispatches two click sequences followed by dblclick event.
Sourcepub async fn context_click(&self) -> Result<()>
pub async fn context_click(&self) -> Result<()>
Right-clicks the element (context menu click).
Dispatches contextmenu event.
Sourcepub async fn hover(&self) -> Result<()>
pub async fn hover(&self) -> Result<()>
Hovers over the element.
Moves mouse to element center and dispatches mouseenter/mouseover events.
Sourcepub async fn mouse_move(&self) -> Result<()>
pub async fn mouse_move(&self) -> Result<()>
Moves mouse to the element center.
Source§impl Element
impl Element
Sourcepub async fn scroll_into_view(&self) -> Result<()>
pub async fn scroll_into_view(&self) -> Result<()>
Scrolls the element into view.
Uses element.scrollIntoView() with smooth behavior.
Sourcepub async fn scroll_into_view_instant(&self) -> Result<()>
pub async fn scroll_into_view_instant(&self) -> Result<()>
Scrolls the element into view immediately (no smooth animation).
Source§impl Element
impl Element
Sourcepub async fn is_checked(&self) -> Result<bool>
pub async fn is_checked(&self) -> Result<bool>
Checks if the element is checked (for checkboxes/radio buttons).
Sourcepub async fn check(&self) -> Result<()>
pub async fn check(&self) -> Result<()>
Checks the checkbox/radio button.
Does nothing if already checked.
Sourcepub async fn uncheck(&self) -> Result<()>
pub async fn uncheck(&self) -> Result<()>
Unchecks the checkbox.
Does nothing if already unchecked.
Sourcepub async fn set_checked(&self, checked: bool) -> Result<()>
pub async fn set_checked(&self, checked: bool) -> Result<()>
Sets the checked state.
Source§impl Element
impl Element
Sourcepub async fn select_by_text(&self, text: &str) -> Result<()>
pub async fn select_by_text(&self, text: &str) -> Result<()>
Sourcepub async fn select_by_value(&self, value: &str) -> Result<()>
pub async fn select_by_value(&self, value: &str) -> Result<()>
Selects an option by value attribute (for <select> elements).
Sourcepub async fn select_by_index(&self, index: usize) -> Result<()>
pub async fn select_by_index(&self, index: usize) -> Result<()>
Selects an option by index (for <select> elements).
Sourcepub async fn get_selected_value(&self) -> Result<Option<String>>
pub async fn get_selected_value(&self) -> Result<Option<String>>
Gets the selected option’s value (for <select> elements).
Sourcepub async fn get_selected_index(&self) -> Result<i64>
pub async fn get_selected_index(&self) -> Result<i64>
Gets the selected option’s index (for <select> elements).
Sourcepub async fn get_selected_text(&self) -> Result<Option<String>>
pub async fn get_selected_text(&self) -> Result<Option<String>>
Gets the selected option’s text (for <select> elements).
Sourcepub async fn is_multiple(&self) -> Result<bool>
pub async fn is_multiple(&self) -> Result<bool>
Checks if this is a multi-select element.
Source§impl Element
impl Element
Sourcepub async fn get_property(&self, name: &str) -> Result<Value>
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§impl Element
impl Element
Sourcepub async fn screenshot(&self) -> Result<String>
pub async fn screenshot(&self) -> Result<String>
Sourcepub async fn screenshot_jpeg(&self, quality: u8) -> Result<String>
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)
Sourcepub async fn screenshot_bytes(&self) -> Result<Vec<u8>>
pub async fn screenshot_bytes(&self) -> Result<Vec<u8>>
Captures a screenshot and returns raw bytes.