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
Sourcepub async fn bounding_box(&self) -> Result<Option<BoundingBox>>
pub async fn bounding_box(&self) -> Result<Option<BoundingBox>>
Returns the bounding box of this element, or None if it is not visible.
The bounding box is in pixels, relative to the top-left corner of the page.
See: https://playwright.dev/docs/api/class-elementhandle#element-handle-bounding-box
Sourcepub async fn scroll_into_view_if_needed(&self) -> Result<()>
pub async fn scroll_into_view_if_needed(&self) -> Result<()>
Scrolls this element into the viewport if it is not already visible.
See: https://playwright.dev/docs/api/class-elementhandle#element-handle-scroll-into-view-if-needed
Sourcepub async fn content_frame(&self) -> Result<Option<Frame>>
pub async fn content_frame(&self) -> Result<Option<Frame>>
Returns the Frame associated with this <iframe> element, or None if
the element is not an iframe.
See: https://playwright.dev/docs/api/class-elementhandle#element-handle-content-frame
Sourcepub async fn owner_frame(&self) -> Result<Option<Frame>>
pub async fn owner_frame(&self) -> Result<Option<Frame>>
Returns the Frame that owns this element.
Every element belongs to a frame (the main frame or a child iframe frame).
See: https://playwright.dev/docs/api/class-elementhandle#element-handle-owner-frame
Sourcepub async fn wait_for_element_state(
&self,
state: &str,
timeout: Option<f64>,
) -> Result<()>
pub async fn wait_for_element_state( &self, state: &str, timeout: Option<f64>, ) -> Result<()>
Waits until the element reaches the specified state.
Valid states: "visible", "hidden", "stable", "enabled", "disabled", "editable".
§Arguments
state— the element state to wait fortimeout— optional timeout in milliseconds (defaults toDEFAULT_TIMEOUT_MS)
See: https://playwright.dev/docs/api/class-elementhandle#element-handle-wait-for-element-state
Trait Implementations§
Source§impl Clone for ElementHandle
impl Clone for ElementHandle
Source§fn clone(&self) -> ElementHandle
fn clone(&self) -> ElementHandle
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more