API ReferenceRustLocator
Locator
Locator mirrors Page's action/query methods (click, fill, hover, press, focus, count, text_content, inner_text, wait_for), each delegating to self.page().<method>(self.selector()). What's below is what a Locator adds: building one semantically instead of by raw CSS, and narrowing it once built.
get_by_role
Finds elements by ARIA role, with name/exact/checked/disabled/expanded/level/pressed/selected/include_hidden filters. Implemented identically on Tab and Locator, so it can start a query or be chained.
pub fn get_by_role_with_options(&self, role: impl Into<String>, options: RoleOptions) -> Locatorget_by_text / get_by_label / get_by_placeholder / get_by_alt_text / get_by_title / get_by_test_id
Finds elements by visible text, associated label, placeholder, alt text, title attribute, or test-id. TextMatcher accepts a literal string or a regex+flags.
pub fn get_by_text_with_options(&self, text: impl Into<TextMatcher>, options: TextOptions) -> LocatorLocator::filter
Narrows matches by has/has_not (nested locator), has_text/has_not_text, and visible. Panics if a nested has/has_not locator belongs to a different page.
pub fn filter(&self, options: LocatorFilterOptions) -> LocatorExample
page.get_by_role("listitem").filter(LocatorFilterOptions { has: Some(page.get_by_role("heading")), ..Default::default() })Locator::not
Excludes elements matching other. Panics if other belongs to a different page.
pub fn not(&self, other: &Locator) -> LocatorLocator::nth / first / last
Selects one match by position — nth accepts negative indices; first/last are shorthands for nth(0)/nth(-1).
pub fn nth(&self, index: i32) -> Locator
pub fn first(&self) -> Locator
pub fn last(&self) -> LocatorLocator::locator
Creates a child locator scoped/chained under this one.
pub fn locator(&self, css_selector: impl Into<String>) -> Locator