Skip to main content

Locator

Struct Locator 

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

A lazy element locator.

Implementations§

Source§

impl Locator

Source

pub fn selector(&self) -> &str

Source

pub fn nth(&self, index: i32) -> Locator

Pick the element at a specific index (disables strict mode).

Source

pub fn first(&self) -> Locator

Source

pub fn last(&self) -> Locator

Source

pub async fn count(&self) -> Result<usize>

Number of matching elements.

Source

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

Source

pub async fn fill(&self, text: &str, _opts: Option<FillOptions>) -> Result<()>

Source

pub async fn type_text(&self, text: &str) -> Result<()>

Source

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

Type each character of text sequentially, optionally pausing between keystrokes. Unlike Self::fill (which sets the value atomically), this dispatches one keyDown/keyUp per character, so it triggers per-keystroke event handlers (e.g. typeahead search).

options.delay is in milliseconds, matching Playwright.

Source

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

Playwright-style alias: type each character sequentially. Mirrors the reserved keyword with a trailing underscore.

Source

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

Source

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

Source

pub async fn focus(&self) -> Result<()>

Source

pub async fn blur(&self) -> Result<()>

Remove focus from the element.

Source

pub async fn input_value(&self, _options: Option<()>) -> Result<String>

The current value of an <input>/<textarea>/<select>.

Source

pub async fn scroll_into_view_if_needed(&self) -> Result<()>

Scroll the element into view.

Source

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

Dispatch a synthetic DOM event on the element.

Source

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

Evaluate expression with the resolved element bound as the first arg.

Source

pub async fn evaluate_handle( &self, page_function: &str, arg: Option<Value>, ) -> Result<JSHandle>

Evaluate page_function with the resolved element bound as the first argument, returning a JSHandle to the resulting remote object (by reference, not by value).

page_function is wrapped as (el, arg) => { return (<page_function>); } and run via Runtime.callFunctionOn with the element’s objectId as the receiver (returnByValue: false). The resolved element is released afterward, mirroring Locator::evaluate.

Source

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

Evaluate expression against all matching elements (bound as an array).

Source

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

Source

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

Source

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

Source

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

Source

pub async fn is_visible(&self) -> Result<bool>

Source

pub async fn is_enabled(&self) -> Result<bool>

Source

pub async fn is_checked(&self) -> Result<bool>

Source

pub async fn is_editable(&self) -> Result<bool>

Source

pub async fn bounding_box(&self) -> Result<Option<BoundingBox>>

Source

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

Wait until the element resolves (and, for actions, is visible).

Source

pub async fn clear(&self, options: Option<FillOptions>) -> Result<()>

Clear an input/textarea (fill with empty string).

Source

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

Double-click (two press/release cycles with clickCount 2).

Source

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

Check a checkbox/radio if not already checked.

Source

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

Uncheck a checkbox if checked.

Source

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

Set the checked state of a checkbox/radio, clicking only if needed.

Source

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

Select an <option> by value/label/index. Returns the now-selected values.

Source

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

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

Source

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

Tap (touch) the element. Approximated as a click on desktop CDP.

Source

pub async fn drag_to( &self, target: &Locator, _options: Option<DragToOptions>, ) -> Result<()>

Drag this element onto target via mouse motion.

Source

pub async fn highlight(&self) -> Result<()>

Highlight this element in the page using CDP’s Overlay domain.

Resolves the element, maps it to a DOM nodeId via DOM.requestNode, then asks the browser to render a translucent box over it (Overlay.highlightNode). Highlighting is purely cosmetic for debugging: it should never fail an action, so any non-fatal CDP error is tolerated and logged away.

Source

pub async fn frame_locator(&self) -> Result<FrameLocator>

If this element is an <iframe>, return a [FrameLocator] scoped to its content document.

The iframe’s content document is reached through its contentDocument, so this is same-origin only (a cross-origin iframe’s contentDocument is null — use the frame’s own target for those). The returned locator is built from the resolved iframe element rather than a selector, so it pins the specific element even if the page’s DOM later shifts.

Source

pub async fn drop(&self, target: &Locator) -> Result<()>

Drag this element and drop it onto target using CDP’s drag events.

Dispatches the HTML5 drag-and-drop event sequence (dragEnterdragOverdrop) on the target, preceded by a dragStart on the source. This is a best-effort implementation: the page must have a drop handler that honors synthetic DataTransfer events. Apps relying on mouse-motion drag (rather than the DnD event API) should use Self::drag_to instead.

Source

pub async fn is_hidden(&self) -> Result<bool>

Source

pub async fn is_disabled(&self) -> Result<bool>

Source

pub async fn is_focused(&self) -> Result<bool>

Source

pub async fn all(&self) -> Result<Vec<Locator>>

All matching locators (one per resolved element).

Source

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

Source

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

Source

pub async fn screenshot( &self, opts: Option<ScreenshotOptions>, ) -> Result<Vec<u8>>

Capture a screenshot clipped to this element.

Source

pub fn filter(&self, options: FilterOptions) -> Locator

Filter matches by text presence (minimal).

Source

pub fn and_(&self, other: &Locator) -> Locator

Chain this locator with another (both must match, in order).

Source

pub fn or_(&self, other: &Locator) -> Locator

Union with another locator (either matches).

Source

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

Find a descendant matching selector.

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_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, test_id: &str) -> Locator

Source

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

Source

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

Capture an aria-snapshot (Playwright’s YAML-ish accessibility-tree format) rooted at this locator’s element.

Resolves the element to its RemoteObjectId, then asks CDP for the partial accessibility tree rooted there (fetchRelatives: false) and serializes it via [crate::aria_snapshot].

Trait Implementations§

Source§

impl Clone for Locator

Source§

fn clone(&self) -> Locator

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§

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