pub struct ElementHandle { /* private fields */ }Expand description
ElementHandle represents a DOM element in the page.
ElementHandles are created via page.query_selector() or frame.query_selector().
They are protocol objects that allow element-specific operations like taking screenshots.
Implementations§
Source§impl ElementHandle
impl ElementHandle
Sourcepub fn new(
parent: Arc<dyn ChannelOwner>,
type_name: String,
guid: Arc<str>,
initializer: Value,
) -> Result<Self>
pub fn new( parent: Arc<dyn ChannelOwner>, type_name: String, guid: Arc<str>, initializer: Value, ) -> Result<Self>
Creates a new ElementHandle from protocol initialization
This is called by the object factory when the server sends a __create__ message
for an ElementHandle object.
Sourcepub async fn screenshot(
&self,
options: Option<ScreenshotOptions>,
) -> Result<Vec<u8>>
pub async fn screenshot( &self, options: Option<ScreenshotOptions>, ) -> Result<Vec<u8>>
Takes a screenshot of the element and returns the image bytes.
The screenshot is captured as PNG by default.
§Example
ⓘ
let playwright = Playwright::launch().await?;
let browser = playwright.chromium().launch().await?;
let page = browser.new_page().await?;
page.goto("https://example.com", None).await?;
let element = page.query_selector("h1").await?.expect("h1 not found");
let screenshot_bytes = element.screenshot(None).await?;See: https://playwright.dev/docs/api/class-elementhandle#element-handle-screenshot
Trait Implementations§
Source§impl ChannelOwner for ElementHandle
impl ChannelOwner for ElementHandle
Source§fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
fn parent(&self) -> Option<Arc<dyn ChannelOwner>>
Returns the parent object, if any. Read more
Source§fn connection(&self) -> Arc<dyn ConnectionLike>
fn connection(&self) -> Arc<dyn ConnectionLike>
Returns the connection this object belongs to.
Source§fn initializer(&self) -> &Value
fn initializer(&self) -> &Value
Returns the raw initializer JSON from the server. Read more
Source§fn dispose(&self, reason: DisposeReason)
fn dispose(&self, reason: DisposeReason)
Disposes this object and all its children. Read more
Source§fn adopt(&self, child: Arc<dyn ChannelOwner>)
fn adopt(&self, child: Arc<dyn ChannelOwner>)
Adopts a child object (moves from old parent to this parent). Read more
Source§fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)
fn add_child(&self, guid: Arc<str>, child: Arc<dyn ChannelOwner>)
Adds a child object to this parent’s registry. Read more
Source§fn remove_child(&self, guid: &str)
fn remove_child(&self, guid: &str)
Removes a child object from this parent’s registry. Read more
Source§fn on_event(&self, _method: &str, _params: Value)
fn on_event(&self, _method: &str, _params: Value)
Handles a protocol event sent to this object. Read more
Source§fn was_collected(&self) -> bool
fn was_collected(&self) -> bool
Returns true if this object was garbage collected.
Source§impl Clone for ElementHandle
impl Clone for ElementHandle
Source§fn clone(&self) -> ElementHandle
fn clone(&self) -> ElementHandle
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !Freeze for ElementHandle
impl !RefUnwindSafe for ElementHandle
impl Send for ElementHandle
impl Sync for ElementHandle
impl Unpin for ElementHandle
impl !UnwindSafe for ElementHandle
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more