Skip to main content

Locator

Struct Locator 

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

A locator for finding and interacting with elements.

Per spec Section 6.1.1: “Unlike Selenium, Locators are strict and auto-wait.”

Implementations§

Source§

impl Locator

Source

pub fn new(selector: impl Into<String>) -> Self

Create a new locator with a CSS selector

Source

pub fn from_selector(selector: Selector) -> Self

Create a locator from a selector

Source

pub fn with_text(self, text: impl Into<String>) -> Self

Filter by text content

Per spec: page.locator("button").with_text("Start Game")

Source

pub fn entity(self, name: impl Into<String>) -> Self

Filter to a specific WASM game entity

Per spec: page.locator("canvas").entity("hero")

Source

pub const fn with_timeout(self, timeout: Duration) -> Self

Set a custom timeout

Source

pub const fn with_strict(self, strict: bool) -> Self

Disable strict mode (allow multiple matches)

Source

pub const fn with_visible(self, visible: bool) -> Self

Set visibility requirement

Source

pub const fn selector(&self) -> &Selector

Get the selector

Source

pub const fn options(&self) -> &LocatorOptions

Get the options

Source

pub fn click(&self) -> ProbarResult<LocatorAction>

Simulate clicking on the located element

§Errors

Returns error if element not found or not clickable

Source

pub fn double_click(&self) -> ProbarResult<LocatorAction>

Simulate double-clicking on the located element

§Errors

Returns error if element not found or not clickable

Source

pub fn drag_to(&self, target: &Point) -> DragBuilder

Drag the located element to a target point

Per spec: hero.drag_to(&Point::new(500.0, 500.0)).steps(10).duration(...)

Source

pub fn fill(&self, text: impl Into<String>) -> ProbarResult<LocatorAction>

Fill the located element with text

§Errors

Returns error if element not found or not fillable

Source

pub fn text_content(&self) -> ProbarResult<LocatorQuery>

Get the text content of the located element

§Errors

Returns error if element not found

Source

pub fn is_visible(&self) -> ProbarResult<LocatorQuery>

Check if the element is visible

Source

pub fn bounding_box(&self) -> ProbarResult<LocatorQuery>

Get the bounding box of the located element

Source

pub fn wait_for_visible(&self) -> ProbarResult<LocatorAction>

Wait for the element to be visible

Source

pub fn wait_for_hidden(&self) -> ProbarResult<LocatorAction>

Wait for the element to be hidden

Source

pub fn count(&self) -> ProbarResult<LocatorQuery>

Check the element count (for assertions)

Source

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

Filter the locator by additional conditions

Per Playwright: locator.filter({ hasText: 'Hello', has: page.locator('.child') })

Source

pub fn and(self, other: Locator) -> Self

Create intersection of two locators (both must match)

Per Playwright: locator.and(other)

Source

pub fn or(self, other: Locator) -> Self

Create union of two locators (either can match)

Per Playwright: locator.or(other)

Source

pub fn first(self) -> Self

Get the first matching element

Per Playwright: locator.first()

Source

pub fn last(self) -> Self

Get the last matching element

Per Playwright: locator.last()

Source

pub fn nth(self, index: usize) -> Self

Get the element at the specified index

Per Playwright: locator.nth(index)

Source

pub fn right_click(&self) -> ProbarResult<LocatorAction>

Simulate right-clicking on the located element

Per Playwright: locator.click({ button: 'right' })

Source

pub fn click_with_options( &self, options: ClickOptions, ) -> ProbarResult<LocatorAction>

Click with custom options

Per Playwright: locator.click(options)

Source

pub fn hover(&self) -> ProbarResult<LocatorAction>

Hover over the located element

Per Playwright: locator.hover()

Source

pub fn focus(&self) -> ProbarResult<LocatorAction>

Focus the located element

Per Playwright: locator.focus()

Source

pub fn blur(&self) -> ProbarResult<LocatorAction>

Remove focus from the located element

Per Playwright: locator.blur()

Source

pub fn check(&self) -> ProbarResult<LocatorAction>

Check a checkbox or radio button

Per Playwright: locator.check()

Source

pub fn uncheck(&self) -> ProbarResult<LocatorAction>

Uncheck a checkbox

Per Playwright: locator.uncheck()

Source

pub fn scroll_into_view(&self) -> ProbarResult<LocatorAction>

Scroll element into view if needed

Per Playwright: locator.scrollIntoViewIfNeeded()

Source

pub fn by_role(role: impl Into<String>) -> Self

Create a locator by ARIA role

Source

pub fn by_role_with_name( role: impl Into<String>, name: impl Into<String>, ) -> Self

Create a locator by ARIA role with name

Source

pub fn by_label(text: impl Into<String>) -> Self

Create a locator by label text

Source

pub fn by_placeholder(text: impl Into<String>) -> Self

Create a locator by placeholder text

Source

pub fn by_alt_text(text: impl Into<String>) -> Self

Create a locator by alt text

Source

pub fn by_test_id(id: impl Into<String>) -> Self

Create a locator by test ID

Source

pub fn by_text(text: impl Into<String>) -> Self

Create a locator by text content

Trait Implementations§

Source§

impl Clone for Locator

Source§

fn clone(&self) -> Locator

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Locator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. 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<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, 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> 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.