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.
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 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 find_element(&self, selector: &str) -> Result<Element>
pub async fn find_element(&self, selector: &str) -> Result<Element>
Finds a child element by CSS selector.
§Errors
Returns Error::ElementNotFound if no matching element exists.
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”)