Skip to main content

Frame

Struct Frame 

Source
pub struct Frame { /* private fields */ }
Expand description

A frame in a page. The main frame wraps the page’s top-level document.

Implementations§

Source§

impl Frame

Source

pub fn page(&self) -> Page

The owning page.

Source

pub fn frame_id(&self) -> &str

CDP frame id.

Source

pub fn name(&self) -> String

Source

pub fn url(&self) -> String

Source

pub fn parent_frame(&self) -> Option<Frame>

Source

pub fn child_frames(&self) -> Vec<Frame>

Source

pub fn is_detached(&self) -> bool

Source

pub async fn evaluate<R: DeserializeOwned>(&self, expression: &str) -> Result<R>

Evaluate expression in this frame’s main world.

Runs in the frame’s own execution context (looked up from the page’s per-frame context map), so for a child <iframe> it acts on the iframe’s document/window, not the top-level page’s.

Source

pub async fn evaluate_handle(&self, expression: &str) -> Result<JSHandle>

Evaluate expression in this frame’s main world, returning a JSHandle to the resulting remote object.

Mirrors Frame::evaluate but returns the object by reference rather than by value. The expression runs in the frame’s own execution context (Runtime.evaluate { contextId }, returnByValue: false); the returned objectId is wrapped in a JSHandle sharing the page’s session.

Source

pub async fn goto( &self, url: &str, opts: Option<GotoOptions>, ) -> Result<Option<Response>>

Navigate this frame to url (main frame only).

Source

pub async fn wait_for_load_state(&self, state: Option<WaitUntil>) -> Result<()>

Source

pub async fn wait_for_function<R: DeserializeOwned>( &self, expression: &str, arg: Option<Value>, options: Option<WaitForFunctionOptions>, ) -> Result<R>

Poll expression until truthy (delegates to the page). See Page::wait_for_function.

Source

pub async fn content(&self) -> Result<String>

The serialized HTML of this frame’s document (documentElement.outerHTML).

Source

pub async fn set_content(&self, html: &str) -> Result<()>

Replace this frame’s document content with html.

Runs document.open()/write()/close() in the frame’s own context, so for a child iframe it rewrites the iframe’s document.

Source

pub async fn title(&self) -> Result<String>

The title of this frame’s document (document.title).

Source

pub fn locator(&self, selector: impl Into<String>) -> Locator

Build a locator scoped to this frame’s execution context.

The resolved locator runs its selector queries in the frame’s own context, so for a child iframe document is the iframe’s document. This is the same-origin scoping mechanism used by Frame::evaluate.

Source

pub fn get_by_text(&self, text: &str, exact: bool) -> Locator

Source

pub fn get_by_label(&self, text: &str) -> Locator

Source

pub fn get_by_role( &self, role: AriaRole, opts: Option<GetByRoleOptions>, ) -> Locator

Source

pub fn get_by_placeholder(&self, text: &str) -> Locator

Source

pub fn get_by_alt_text(&self, text: &str) -> Locator

Source

pub fn get_by_title(&self, text: &str) -> Locator

Source

pub fn get_by_test_id(&self, text: &str) -> Locator

Source

pub async fn add_script_tag( &self, opts: Option<AddScriptTagOptions>, ) -> Result<()>

Inject a <script> tag into this frame.

Either url (external script) or source (inline script text) must be provided; type sets the <script type=...> attribute.

Implemented via DOM injection in the frame’s own execution context, so document.head is this frame’s <head> — for a child iframe the script is injected into (and executes within) the iframe’s document.

Source

pub async fn add_style_tag( &self, opts: Option<AddStyleTagOptions>, ) -> Result<()>

Inject a <link rel=stylesheet>/<style> tag into this frame.

Either url (external stylesheet) or source (inline CSS) must be provided. Runs in the frame’s own context, so it targets this frame’s <head>.

Source

pub async fn wait_for_url( &self, url: &str, opts: Option<FrameWaitForUrlOptions>, ) -> Result<()>

Wait until this frame’s URL matches url (exact, or * glob).

Subscribes to the page session and watches Page.frameNavigated / Page.lifecycleEvent events for this frame, falling back to the cached frame tree URL. On match, optionally waits for a lifecycle state.

Source

pub async fn click( &self, selector: &str, opts: Option<ClickOptions>, ) -> Result<()>

Click the first element matching selector.

Source

pub async fn dblclick( &self, selector: &str, opts: Option<ClickOptions>, ) -> Result<()>

Double-click the first element matching selector.

Source

pub async fn fill( &self, selector: &str, value: &str, opts: Option<FillOptions>, ) -> Result<()>

Set the value of the first matching <input>/<textarea> to value.

Source

pub async fn focus(&self, selector: &str) -> Result<()>

Focus the first element matching selector.

Source

pub async fn hover( &self, selector: &str, opts: Option<HoverOptions>, ) -> Result<()>

Hover the first element matching selector.

Source

pub async fn press( &self, selector: &str, key: &str, opts: Option<PressOptions>, ) -> Result<()>

Press key on the first element matching selector.

Source

pub async fn select_option( &self, selector: &str, value: impl Into<SelectOption>, opts: Option<SelectOptions>, ) -> Result<Vec<String>>

Select <option>(s) on the first matching <select> by value/label/index.

Source

pub async fn set_input_files( &self, selector: &str, files: &[&str], ) -> Result<()>

Set files on the first matching <input type=file> by server-side path(s).

Source

pub async fn tap( &self, selector: &str, opts: Option<ClickOptions>, ) -> Result<()>

Tap (touch) the first element matching selector.

Source

pub async fn check( &self, selector: &str, opts: Option<CheckOptions>, ) -> Result<()>

Check the first matching checkbox/radio.

Source

pub async fn uncheck( &self, selector: &str, opts: Option<CheckOptions>, ) -> Result<()>

Uncheck the first matching checkbox.

Source

pub async fn set_checked( &self, selector: &str, checked: bool, opts: Option<CheckOptions>, ) -> Result<()>

Set the checked state of the first matching checkbox/radio.

Source

pub async fn type_( &self, selector: &str, text: &str, opts: Option<PressSequentiallyOptions>, ) -> Result<()>

Type text into the first element matching selector (fill-based).

Source

pub async fn text_content(&self, selector: &str) -> Result<Option<String>>

The textContent of the first element matching selector, if any.

Source

pub async fn inner_text(&self, selector: &str) -> Result<String>

The visible text of the first element matching selector.

Source

pub async fn inner_html(&self, selector: &str) -> Result<String>

The serialized HTML of the first element matching selector.

Source

pub async fn get_attribute( &self, selector: &str, name: &str, ) -> Result<Option<String>>

The value of attribute name on the first element matching selector.

Source

pub async fn count(&self, selector: &str) -> Result<usize>

Number of elements matching selector in this frame.

Source

pub async fn wait_for_selector( &self, selector: &str, opts: Option<WaitForOptions>, ) -> Result<()>

Wait until an element matching selector resolves in this frame.

Source

pub async fn eval_on_selector<R: DeserializeOwned>( &self, selector: &str, expression: &str, ) -> Result<R>

Evaluate expression against the first element matching selector in this frame.

Source

pub async fn eval_on_selector_all<R: DeserializeOwned>( &self, selector: &str, expression: &str, ) -> Result<Vec<R>>

Evaluate expression against all elements matching selector in this frame.

Source

pub async fn dispatch_event( &self, selector: &str, type_: &str, init: Option<Value>, ) -> Result<()>

Dispatch a synthetic DOM event on the first element matching selector.

Source

pub async fn drag_and_drop( &self, source: &str, target: &str, opts: Option<DragToOptions>, ) -> Result<()>

Drag the element matching source onto the element matching target.

Source

pub async fn query_selector( &self, selector: &str, ) -> Result<Option<ElementHandle>>

The first element matching selector in this frame, if any.

Source

pub async fn query_selector_all( &self, selector: &str, ) -> Result<Vec<ElementHandle>>

All elements matching selector in this frame.

Trait Implementations§

Source§

impl Clone for Frame

Source§

fn clone(&self) -> Frame

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Frame

§

impl !UnwindSafe for Frame

§

impl Freeze for Frame

§

impl Send for Frame

§

impl Sync for Frame

§

impl Unpin for Frame

§

impl UnsafeUnpin for Frame

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more