pub struct ElementHandle { /* private fields */ }Expand description
A handle to a resolved element.
Implementations§
Source§impl ElementHandle
impl ElementHandle
pub async fn click(&self, options: Option<ClickOptions>) -> Result<()>
pub async fn fill(&self, text: &str, _opts: Option<FillOptions>) -> Result<()>
Sourcepub async fn clear(&self, options: Option<FillOptions>) -> Result<()>
pub async fn clear(&self, options: Option<FillOptions>) -> Result<()>
Clear an input/textarea (fill with the empty string).
Sourcepub async fn type_(
&self,
text: &str,
opts: Option<PressSequentiallyOptions>,
) -> Result<()>
pub async fn type_( &self, text: &str, opts: Option<PressSequentiallyOptions>, ) -> Result<()>
Type each character of text sequentially with an optional delay.
Dispatches one char key event per character (so per-keystroke handlers
fire). The element is focused first.
Sourcepub async fn press(
&self,
key: &str,
options: Option<PressOptions>,
) -> Result<()>
pub async fn press( &self, key: &str, options: Option<PressOptions>, ) -> Result<()>
Press a single key (focus + keyDown/keyUp).
Sourcepub async fn dblclick(&self, options: Option<ClickOptions>) -> Result<()>
pub async fn dblclick(&self, options: Option<ClickOptions>) -> Result<()>
Double-click (clickCount 2).
Sourcepub async fn tap(&self, options: Option<ClickOptions>) -> Result<()>
pub async fn tap(&self, options: Option<ClickOptions>) -> Result<()>
Tap (touch) the element. Approximated as a click on desktop CDP.
Sourcepub async fn check(&self, options: Option<CheckOptions>) -> Result<()>
pub async fn check(&self, options: Option<CheckOptions>) -> Result<()>
Check a checkbox/radio if not already checked.
Sourcepub async fn uncheck(&self, options: Option<CheckOptions>) -> Result<()>
pub async fn uncheck(&self, options: Option<CheckOptions>) -> Result<()>
Uncheck a checkbox if checked.
Sourcepub async fn set_checked(
&self,
checked: bool,
options: Option<CheckOptions>,
) -> Result<()>
pub async fn set_checked( &self, checked: bool, options: Option<CheckOptions>, ) -> Result<()>
Set the checked state of a checkbox/radio, clicking only if needed.
Sourcepub async fn select_option(
&self,
value: impl Into<SelectOption>,
_options: Option<SelectOptions>,
) -> Result<Vec<String>>
pub async fn select_option( &self, value: impl Into<SelectOption>, _options: Option<SelectOptions>, ) -> Result<Vec<String>>
Select an <option> by value/label/index. Returns the now-selected values.
Sourcepub async fn drag_and_drop(
&self,
target: &ElementHandle,
_options: Option<DragToOptions>,
) -> Result<()>
pub async fn drag_and_drop( &self, target: &ElementHandle, _options: Option<DragToOptions>, ) -> Result<()>
Drag this element onto target via mouse motion.
pub async fn focus(&self) -> Result<()>
pub async fn blur(&self) -> Result<()>
pub async fn scroll_into_view_if_needed(&self) -> Result<()>
pub async fn dispatch_event( &self, type_: &str, init: Option<Value>, ) -> Result<()>
pub async fn text_content(&self) -> Result<Option<String>>
pub async fn inner_text(&self) -> Result<String>
pub async fn inner_html(&self) -> Result<String>
pub async fn get_attribute(&self, name: &str) -> Result<Option<String>>
Sourcepub async fn evaluate<R: DeserializeOwned>(
&self,
expression: &str,
arg: Option<Value>,
) -> Result<R>
pub async fn evaluate<R: DeserializeOwned>( &self, expression: &str, arg: Option<Value>, ) -> Result<R>
Evaluate expression with this element bound as the first argument.
Sourcepub async fn evaluate_handle(
&self,
page_function: &str,
arg: Option<Value>,
) -> Result<JSHandle>
pub async fn evaluate_handle( &self, page_function: &str, arg: Option<Value>, ) -> Result<JSHandle>
Evaluate page_function with this element bound as the first argument,
returning a JSHandle to the resulting
remote object (by reference, not by value).
page_function is wrapped as (el, arg) => { return (<page_function>); }
and run via Runtime.callFunctionOn against this handle’s objectId
(returnByValue: false), mirroring ElementHandle::evaluate.
pub async fn is_visible(&self) -> Result<bool>
pub async fn is_enabled(&self) -> Result<bool>
pub async fn is_checked(&self) -> Result<bool>
pub async fn is_editable(&self) -> Result<bool>
pub async fn bounding_box(&self) -> Result<Option<BoundingBox>>
pub async fn screenshot( &self, opts: Option<ScreenshotOptions>, ) -> Result<Vec<u8>>
Sourcepub async fn set_input_files(&self, files: &[&str]) -> Result<()>
pub async fn set_input_files(&self, files: &[&str]) -> Result<()>
Set files on an <input type=file> by server-side path(s).
Sourcepub async fn dispose(&self) -> Result<()>
pub async fn dispose(&self) -> Result<()>
Release the remote object eagerly (otherwise browser GCs it on navigation).
Sourcepub async fn content_frame(&self) -> Result<Option<Frame>>
pub async fn content_frame(&self) -> Result<Option<Frame>>
If this element is an <iframe>, return its content Frame; else None.
The frame id is read from the DOM node’s contentDocument.frameId.
Best-effort: returns None if the element is not a frame or the content
frame cannot be resolved (e.g. cross-origin, where contentDocument is
inaccessible from the embedding context).
Sourcepub async fn owner_frame(&self) -> Result<Option<Frame>>
pub async fn owner_frame(&self) -> Result<Option<Frame>>
The Frame that owns this element.
Resolves the element’s owner execution context via the remote object’s frame (DOM.describeNode → frameId on the owning document), falling back to the page’s main frame. Best-effort.
Sourcepub async fn wait_for_element_state(&self, state: ElementState) -> Result<()>
pub async fn wait_for_element_state(&self, state: ElementState) -> Result<()>
Poll until this element reaches the requested ElementState, using the
page’s default timeout.
Stable is detected by sampling the bounding box twice and checking that
it did not move; the other states query the injected element-state helper.
Sourcepub async fn count(&self) -> Result<usize>
pub async fn count(&self) -> Result<usize>
Always 1 — an ElementHandle pins exactly one element. Provided for
API parity with Locator::count; a disposed or
GC’d handle will still report 1 (use Self::is_visible to check it).
Trait Implementations§
Source§impl Clone for ElementHandle
impl Clone for ElementHandle
Source§fn clone(&self) -> ElementHandle
fn clone(&self) -> ElementHandle
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more