pub struct Locator { /* private fields */ }Expand description
A lazy handle to a DOM element identified by a CSS selector.
Locators are created with Page::locator and make the common
“find-then-act” pattern ergonomic and composable.
§Example
let browser = Browser::launch().await?;
let page = browser.new_page().await?;
page.goto("https://example.com", WaitUntil::Load).await?;
// Locator API
page.locator("button#submit").click().await?;
page.locator("input[name=q]").type_text("hello").await?;
page.locator(".result").wait_for().await?;Implementations§
Source§impl Locator
impl Locator
Sourcepub async fn type_text(&self, text: &str) -> Result<()>
pub async fn type_text(&self, text: &str) -> Result<()>
Type text into the element identified by this locator.
Sourcepub async fn wait_for(&self) -> Result<()>
pub async fn wait_for(&self) -> Result<()>
Wait until the element is present in the DOM (30 s default timeout).
Sourcepub async fn wait_for_timeout(&self, dur: Duration) -> Result<()>
pub async fn wait_for_timeout(&self, dur: Duration) -> Result<()>
Wait until the element is present with a custom timeout.
Sourcepub async fn inner_text(&self) -> Result<String>
pub async fn inner_text(&self) -> Result<String>
Get the inner text of the element.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Locator
impl !RefUnwindSafe for Locator
impl Send for Locator
impl Sync for Locator
impl Unpin for Locator
impl UnsafeUnpin for Locator
impl !UnwindSafe for Locator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more