pub struct Locator { /* private fields */ }Expand description
A lazy element locator.
Implementations§
Source§impl Locator
impl Locator
pub fn selector(&self) -> &str
Sourcepub fn nth(&self, index: i32) -> Locator
pub fn nth(&self, index: i32) -> Locator
Pick the element at a specific index (disables strict mode).
pub fn first(&self) -> Locator
pub fn last(&self) -> Locator
pub async fn click(&self, opts: Option<ClickOptions>) -> Result<()>
pub async fn fill(&self, text: &str, _opts: Option<FillOptions>) -> Result<()>
pub async fn type_text(&self, text: &str) -> Result<()>
Sourcepub async fn press_sequentially(
&self,
text: &str,
opts: Option<PressSequentiallyOptions>,
) -> Result<()>
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.
Sourcepub async fn type_(
&self,
text: &str,
opts: Option<PressSequentiallyOptions>,
) -> Result<()>
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.
pub async fn press( &self, key: &str, options: Option<PressOptions>, ) -> Result<()>
pub async fn hover(&self, opts: Option<HoverOptions>) -> Result<()>
pub async fn focus(&self) -> Result<()>
Sourcepub async fn input_value(&self, _options: Option<()>) -> Result<String>
pub async fn input_value(&self, _options: Option<()>) -> Result<String>
The current value of an <input>/<textarea>/<select>.
Sourcepub async fn scroll_into_view_if_needed(&self) -> Result<()>
pub async fn scroll_into_view_if_needed(&self) -> Result<()>
Scroll the element into view.
Sourcepub async fn dispatch_event(
&self,
type_: &str,
init: Option<Value>,
) -> Result<()>
pub async fn dispatch_event( &self, type_: &str, init: Option<Value>, ) -> Result<()>
Dispatch a synthetic DOM event on the element.
Sourcepub async fn evaluate<R: DeserializeOwned>(
&self,
expression: &str,
arg: Option<Value>,
) -> Result<R>
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.
Sourcepub async fn evaluate_handle(
&self,
page_function: &str,
arg: Option<Value>,
) -> Result<JSHandle>
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.
Sourcepub async fn evaluate_all<R: DeserializeOwned>(
&self,
expression: &str,
arg: Option<Value>,
) -> Result<R>
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).
pub async fn text_content(&self) -> Result<Option<String>>
pub async fn inner_text(&self) -> Result<String>
pub async fn inner_html(&self) -> Result<String>
pub async fn get_attribute(&self, name: &str) -> Result<Option<String>>
pub async fn is_visible(&self) -> Result<bool>
pub async fn is_enabled(&self) -> Result<bool>
pub async fn is_checked(&self) -> Result<bool>
pub async fn is_editable(&self) -> Result<bool>
pub async fn bounding_box(&self) -> Result<Option<BoundingBox>>
Sourcepub async fn wait_for(&self, opts: Option<WaitForOptions>) -> Result<()>
pub async fn wait_for(&self, opts: Option<WaitForOptions>) -> Result<()>
Wait until the element resolves (and, for actions, is visible).
Sourcepub async fn clear(&self, options: Option<FillOptions>) -> Result<()>
pub async fn clear(&self, options: Option<FillOptions>) -> Result<()>
Clear an input/textarea (fill with empty string).
Sourcepub async fn dblclick(&self, options: Option<ClickOptions>) -> Result<()>
pub async fn dblclick(&self, options: Option<ClickOptions>) -> Result<()>
Double-click (two press/release cycles with clickCount 2).
Sourcepub async fn check(&self, options: Option<CheckOptions>) -> Result<()>
pub async fn check(&self, options: Option<CheckOptions>) -> Result<()>
Check a checkbox/radio if not already checked.
Sourcepub async fn uncheck(&self, options: Option<CheckOptions>) -> Result<()>
pub async fn uncheck(&self, options: Option<CheckOptions>) -> Result<()>
Uncheck a checkbox if checked.
Sourcepub async fn set_checked(
&self,
checked: bool,
options: Option<CheckOptions>,
) -> Result<()>
pub async fn set_checked( &self, checked: bool, options: Option<CheckOptions>, ) -> Result<()>
Set the checked state of a checkbox/radio, clicking only if needed.
Sourcepub async fn select_option(
&self,
value: impl Into<SelectOption>,
_options: Option<SelectOptions>,
) -> Result<Vec<String>>
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.
Sourcepub async fn set_input_files(&self, files: &[&str]) -> Result<()>
pub async fn set_input_files(&self, files: &[&str]) -> Result<()>
Set files on an <input type=file> by server-side path(s).
Sourcepub async fn tap(&self, options: Option<ClickOptions>) -> Result<()>
pub async fn tap(&self, options: Option<ClickOptions>) -> Result<()>
Tap (touch) the element. Approximated as a click on desktop CDP.
Sourcepub async fn drag_to(
&self,
target: &Locator,
_options: Option<DragToOptions>,
) -> Result<()>
pub async fn drag_to( &self, target: &Locator, _options: Option<DragToOptions>, ) -> Result<()>
Drag this element onto target via mouse motion.
Sourcepub async fn highlight(&self) -> Result<()>
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.
Sourcepub async fn frame_locator(&self) -> Result<FrameLocator>
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.
Sourcepub async fn drop(&self, target: &Locator) -> Result<()>
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
(dragEnter → dragOver → drop) 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.
pub async fn is_disabled(&self) -> Result<bool>
pub async fn is_focused(&self) -> Result<bool>
Sourcepub async fn all(&self) -> Result<Vec<Locator>>
pub async fn all(&self) -> Result<Vec<Locator>>
All matching locators (one per resolved element).
pub async fn all_inner_texts(&self) -> Result<Vec<String>>
pub async fn all_text_contents(&self) -> Result<Vec<String>>
Sourcepub async fn screenshot(
&self,
opts: Option<ScreenshotOptions>,
) -> Result<Vec<u8>>
pub async fn screenshot( &self, opts: Option<ScreenshotOptions>, ) -> Result<Vec<u8>>
Capture a screenshot clipped to this element.
Sourcepub fn filter(&self, options: FilterOptions) -> Locator
pub fn filter(&self, options: FilterOptions) -> Locator
Filter matches by text presence (minimal).
Sourcepub fn and_(&self, other: &Locator) -> Locator
pub fn and_(&self, other: &Locator) -> Locator
Chain this locator with another (both must match, in order).
Sourcepub fn locator(&self, selector: impl Into<String>) -> Locator
pub fn locator(&self, selector: impl Into<String>) -> Locator
Find a descendant matching selector.
pub fn get_by_text(&self, text: &str, _exact: bool) -> Locator
pub fn get_by_label(&self, text: &str) -> 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, test_id: &str) -> Locator
pub fn get_by_role( &self, role: AriaRole, opts: Option<GetByRoleOptions>, ) -> Locator
Sourcepub async fn aria_snapshot(&self) -> Result<String>
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].