pub struct ElementHandle<'a> { /* private fields */ }Expand description
A handle to a DOM element.
Unlike [Locator], an ElementHandle is bound to a specific element instance.
If the element is removed from the DOM, the handle becomes stale.
Most operations should prefer using [Locator] for its auto-waiting and
re-querying capabilities. Use ElementHandle only when you need:
- To pass an element reference to JavaScript
- Low-level DOM operations
- Box model information
Implementations§
Source§impl ElementHandle<'_>
impl ElementHandle<'_>
Sourcepub fn object_id(&self) -> &str
pub fn object_id(&self) -> &str
Get the object ID of this element handle.
This is the CDP remote object ID that can be used for further CDP calls.
Sourcepub async fn box_model(&self) -> Result<Option<BoxModel>, LocatorError>
pub async fn box_model(&self) -> Result<Option<BoxModel>, LocatorError>
Get the box model of the element.
Returns detailed information about the element’s box model including content, padding, border, and margin boxes.
§Errors
Returns an error if the element is no longer attached to the DOM.
Sourcepub async fn is_attached(&self) -> Result<bool, LocatorError>
pub async fn is_attached(&self) -> Result<bool, LocatorError>
Check if the element is still attached to the DOM.
Returns true if the element still exists in the document.
Sourcepub async fn evaluate<T: DeserializeOwned>(
&self,
expression: &str,
) -> Result<T, LocatorError>
pub async fn evaluate<T: DeserializeOwned>( &self, expression: &str, ) -> Result<T, LocatorError>
Evaluate a JavaScript expression with this element as this.
§Example
use viewpoint_core::Page;
use viewpoint_js::js;
let handle = page.locator("button").element_handle().await?;
let text: String = handle.evaluate(js!{ this.textContent }).await?;