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
impl Locator
Sourcepub fn from_selector(selector: Selector) -> Self
pub fn from_selector(selector: Selector) -> Self
Create a locator from a selector
Sourcepub fn with_text(self, text: impl Into<String>) -> Self
pub fn with_text(self, text: impl Into<String>) -> Self
Filter by text content
Per spec: page.locator("button").with_text("Start Game")
Sourcepub fn entity(self, name: impl Into<String>) -> Self
pub fn entity(self, name: impl Into<String>) -> Self
Filter to a specific WASM game entity
Per spec: page.locator("canvas").entity("hero")
Sourcepub const fn with_timeout(self, timeout: Duration) -> Self
pub const fn with_timeout(self, timeout: Duration) -> Self
Set a custom timeout
Sourcepub const fn with_strict(self, strict: bool) -> Self
pub const fn with_strict(self, strict: bool) -> Self
Disable strict mode (allow multiple matches)
Sourcepub const fn with_visible(self, visible: bool) -> Self
pub const fn with_visible(self, visible: bool) -> Self
Set visibility requirement
Sourcepub const fn options(&self) -> &LocatorOptions
pub const fn options(&self) -> &LocatorOptions
Get the options
Sourcepub fn click(&self) -> ProbarResult<LocatorAction>
pub fn click(&self) -> ProbarResult<LocatorAction>
Simulate clicking on the located element
§Errors
Returns error if element not found or not clickable
Sourcepub fn double_click(&self) -> ProbarResult<LocatorAction>
pub fn double_click(&self) -> ProbarResult<LocatorAction>
Simulate double-clicking on the located element
§Errors
Returns error if element not found or not clickable
Sourcepub fn drag_to(&self, target: &Point) -> DragBuilder
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(...)
Sourcepub fn fill(&self, text: impl Into<String>) -> ProbarResult<LocatorAction>
pub fn fill(&self, text: impl Into<String>) -> ProbarResult<LocatorAction>
Sourcepub fn text_content(&self) -> ProbarResult<LocatorQuery>
pub fn text_content(&self) -> ProbarResult<LocatorQuery>
Sourcepub fn is_visible(&self) -> ProbarResult<LocatorQuery>
pub fn is_visible(&self) -> ProbarResult<LocatorQuery>
Check if the element is visible
Sourcepub fn bounding_box(&self) -> ProbarResult<LocatorQuery>
pub fn bounding_box(&self) -> ProbarResult<LocatorQuery>
Get the bounding box of the located element
Sourcepub fn wait_for_visible(&self) -> ProbarResult<LocatorAction>
pub fn wait_for_visible(&self) -> ProbarResult<LocatorAction>
Wait for the element to be visible
Wait for the element to be hidden
Sourcepub fn count(&self) -> ProbarResult<LocatorQuery>
pub fn count(&self) -> ProbarResult<LocatorQuery>
Check the element count (for assertions)
Sourcepub fn filter(self, options: FilterOptions) -> Self
pub fn filter(self, options: FilterOptions) -> Self
Filter the locator by additional conditions
Per Playwright: locator.filter({ hasText: 'Hello', has: page.locator('.child') })
Sourcepub fn and(self, other: Locator) -> Self
pub fn and(self, other: Locator) -> Self
Create intersection of two locators (both must match)
Per Playwright: locator.and(other)
Sourcepub fn or(self, other: Locator) -> Self
pub fn or(self, other: Locator) -> Self
Create union of two locators (either can match)
Per Playwright: locator.or(other)
Sourcepub fn nth(self, index: usize) -> Self
pub fn nth(self, index: usize) -> Self
Get the element at the specified index
Per Playwright: locator.nth(index)
Sourcepub fn right_click(&self) -> ProbarResult<LocatorAction>
pub fn right_click(&self) -> ProbarResult<LocatorAction>
Simulate right-clicking on the located element
Per Playwright: locator.click({ button: 'right' })
Sourcepub fn click_with_options(
&self,
options: ClickOptions,
) -> ProbarResult<LocatorAction>
pub fn click_with_options( &self, options: ClickOptions, ) -> ProbarResult<LocatorAction>
Click with custom options
Per Playwright: locator.click(options)
Sourcepub fn hover(&self) -> ProbarResult<LocatorAction>
pub fn hover(&self) -> ProbarResult<LocatorAction>
Hover over the located element
Per Playwright: locator.hover()
Sourcepub fn focus(&self) -> ProbarResult<LocatorAction>
pub fn focus(&self) -> ProbarResult<LocatorAction>
Focus the located element
Per Playwright: locator.focus()
Sourcepub fn blur(&self) -> ProbarResult<LocatorAction>
pub fn blur(&self) -> ProbarResult<LocatorAction>
Remove focus from the located element
Per Playwright: locator.blur()
Sourcepub fn check(&self) -> ProbarResult<LocatorAction>
pub fn check(&self) -> ProbarResult<LocatorAction>
Check a checkbox or radio button
Per Playwright: locator.check()
Sourcepub fn uncheck(&self) -> ProbarResult<LocatorAction>
pub fn uncheck(&self) -> ProbarResult<LocatorAction>
Uncheck a checkbox
Per Playwright: locator.uncheck()
Sourcepub fn scroll_into_view(&self) -> ProbarResult<LocatorAction>
pub fn scroll_into_view(&self) -> ProbarResult<LocatorAction>
Scroll element into view if needed
Per Playwright: locator.scrollIntoViewIfNeeded()
Sourcepub fn by_role_with_name(
role: impl Into<String>,
name: impl Into<String>,
) -> Self
pub fn by_role_with_name( role: impl Into<String>, name: impl Into<String>, ) -> Self
Create a locator by ARIA role with name
Sourcepub fn by_placeholder(text: impl Into<String>) -> Self
pub fn by_placeholder(text: impl Into<String>) -> Self
Create a locator by placeholder text
Sourcepub fn by_alt_text(text: impl Into<String>) -> Self
pub fn by_alt_text(text: impl Into<String>) -> Self
Create a locator by alt text
Sourcepub fn by_test_id(id: impl Into<String>) -> Self
pub fn by_test_id(id: impl Into<String>) -> Self
Create a locator by test ID