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
impl Frame
pub fn name(&self) -> String
pub fn url(&self) -> String
pub fn parent_frame(&self) -> Option<Frame>
pub fn child_frames(&self) -> Vec<Frame>
pub fn is_detached(&self) -> bool
Sourcepub async fn evaluate<R: DeserializeOwned>(&self, expression: &str) -> Result<R>
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.
Sourcepub async fn evaluate_handle(&self, expression: &str) -> Result<JSHandle>
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.
Sourcepub async fn goto(
&self,
url: &str,
opts: Option<GotoOptions>,
) -> Result<Option<Response>>
pub async fn goto( &self, url: &str, opts: Option<GotoOptions>, ) -> Result<Option<Response>>
Navigate this frame to url (main frame only).
pub async fn wait_for_load_state(&self, state: Option<WaitUntil>) -> Result<()>
Sourcepub async fn wait_for_function<R: DeserializeOwned>(
&self,
expression: &str,
arg: Option<Value>,
options: Option<WaitForFunctionOptions>,
) -> Result<R>
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.
Sourcepub async fn content(&self) -> Result<String>
pub async fn content(&self) -> Result<String>
The serialized HTML of this frame’s document (documentElement.outerHTML).
Sourcepub async fn set_content(&self, html: &str) -> Result<()>
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.
Sourcepub async fn title(&self) -> Result<String>
pub async fn title(&self) -> Result<String>
The title of this frame’s document (document.title).
Sourcepub fn locator(&self, selector: impl Into<String>) -> Locator
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.
pub fn get_by_text(&self, text: &str, exact: bool) -> Locator
pub fn get_by_label(&self, text: &str) -> Locator
pub fn get_by_role( &self, role: AriaRole, opts: Option<GetByRoleOptions>, ) -> Locator
pub fn get_by_placeholder(&self, text: &str) -> Locator
pub fn get_by_alt_text(&self, text: &str) -> Locator
pub fn get_by_title(&self, text: &str) -> Locator
pub fn get_by_test_id(&self, text: &str) -> Locator
Sourcepub async fn add_script_tag(
&self,
opts: Option<AddScriptTagOptions>,
) -> Result<()>
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.
Sourcepub async fn add_style_tag(
&self,
opts: Option<AddStyleTagOptions>,
) -> Result<()>
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>.
Sourcepub async fn wait_for_url(
&self,
url: &str,
opts: Option<FrameWaitForUrlOptions>,
) -> Result<()>
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.
Sourcepub async fn click(
&self,
selector: &str,
opts: Option<ClickOptions>,
) -> Result<()>
pub async fn click( &self, selector: &str, opts: Option<ClickOptions>, ) -> Result<()>
Click the first element matching selector.
Sourcepub async fn dblclick(
&self,
selector: &str,
opts: Option<ClickOptions>,
) -> Result<()>
pub async fn dblclick( &self, selector: &str, opts: Option<ClickOptions>, ) -> Result<()>
Double-click the first element matching selector.
Sourcepub async fn fill(
&self,
selector: &str,
value: &str,
opts: Option<FillOptions>,
) -> Result<()>
pub async fn fill( &self, selector: &str, value: &str, opts: Option<FillOptions>, ) -> Result<()>
Set the value of the first matching <input>/<textarea> to value.
Sourcepub async fn focus(&self, selector: &str) -> Result<()>
pub async fn focus(&self, selector: &str) -> Result<()>
Focus the first element matching selector.
Sourcepub async fn hover(
&self,
selector: &str,
opts: Option<HoverOptions>,
) -> Result<()>
pub async fn hover( &self, selector: &str, opts: Option<HoverOptions>, ) -> Result<()>
Hover the first element matching selector.
Sourcepub async fn press(
&self,
selector: &str,
key: &str,
opts: Option<PressOptions>,
) -> Result<()>
pub async fn press( &self, selector: &str, key: &str, opts: Option<PressOptions>, ) -> Result<()>
Press key on the first element matching selector.
Sourcepub async fn select_option(
&self,
selector: &str,
value: impl Into<SelectOption>,
opts: Option<SelectOptions>,
) -> Result<Vec<String>>
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.
Sourcepub async fn set_input_files(
&self,
selector: &str,
files: &[&str],
) -> Result<()>
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).
Sourcepub async fn tap(
&self,
selector: &str,
opts: Option<ClickOptions>,
) -> Result<()>
pub async fn tap( &self, selector: &str, opts: Option<ClickOptions>, ) -> Result<()>
Tap (touch) the first element matching selector.
Sourcepub async fn check(
&self,
selector: &str,
opts: Option<CheckOptions>,
) -> Result<()>
pub async fn check( &self, selector: &str, opts: Option<CheckOptions>, ) -> Result<()>
Check the first matching checkbox/radio.
Sourcepub async fn uncheck(
&self,
selector: &str,
opts: Option<CheckOptions>,
) -> Result<()>
pub async fn uncheck( &self, selector: &str, opts: Option<CheckOptions>, ) -> Result<()>
Uncheck the first matching checkbox.
Sourcepub async fn set_checked(
&self,
selector: &str,
checked: bool,
opts: Option<CheckOptions>,
) -> Result<()>
pub async fn set_checked( &self, selector: &str, checked: bool, opts: Option<CheckOptions>, ) -> Result<()>
Set the checked state of the first matching checkbox/radio.
Sourcepub async fn type_(
&self,
selector: &str,
text: &str,
opts: Option<PressSequentiallyOptions>,
) -> Result<()>
pub async fn type_( &self, selector: &str, text: &str, opts: Option<PressSequentiallyOptions>, ) -> Result<()>
Type text into the first element matching selector (fill-based).
Sourcepub async fn text_content(&self, selector: &str) -> Result<Option<String>>
pub async fn text_content(&self, selector: &str) -> Result<Option<String>>
The textContent of the first element matching selector, if any.
Sourcepub async fn inner_text(&self, selector: &str) -> Result<String>
pub async fn inner_text(&self, selector: &str) -> Result<String>
The visible text of the first element matching selector.
Sourcepub async fn inner_html(&self, selector: &str) -> Result<String>
pub async fn inner_html(&self, selector: &str) -> Result<String>
The serialized HTML of the first element matching selector.
Sourcepub async fn get_attribute(
&self,
selector: &str,
name: &str,
) -> Result<Option<String>>
pub async fn get_attribute( &self, selector: &str, name: &str, ) -> Result<Option<String>>
The value of attribute name on the first element matching selector.
Sourcepub async fn count(&self, selector: &str) -> Result<usize>
pub async fn count(&self, selector: &str) -> Result<usize>
Number of elements matching selector in this frame.
Sourcepub async fn wait_for_selector(
&self,
selector: &str,
opts: Option<WaitForOptions>,
) -> Result<()>
pub async fn wait_for_selector( &self, selector: &str, opts: Option<WaitForOptions>, ) -> Result<()>
Wait until an element matching selector resolves in this frame.
Sourcepub async fn eval_on_selector<R: DeserializeOwned>(
&self,
selector: &str,
expression: &str,
) -> Result<R>
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.
Sourcepub async fn eval_on_selector_all<R: DeserializeOwned>(
&self,
selector: &str,
expression: &str,
) -> Result<Vec<R>>
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.
Sourcepub async fn dispatch_event(
&self,
selector: &str,
type_: &str,
init: Option<Value>,
) -> Result<()>
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.
Sourcepub async fn drag_and_drop(
&self,
source: &str,
target: &str,
opts: Option<DragToOptions>,
) -> Result<()>
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.
Sourcepub async fn query_selector(
&self,
selector: &str,
) -> Result<Option<ElementHandle>>
pub async fn query_selector( &self, selector: &str, ) -> Result<Option<ElementHandle>>
The first element matching selector in this frame, if any.
Sourcepub async fn query_selector_all(
&self,
selector: &str,
) -> Result<Vec<ElementHandle>>
pub async fn query_selector_all( &self, selector: &str, ) -> Result<Vec<ElementHandle>>
All elements matching selector in this frame.