pub struct By { /* private fields */ }Expand description
Element Selector struct providing a convenient way to specify selectors.
§Scope when querying from a WebElement
When you call find / find_all / query on a WebElement (rather
than on a WebDriver), thirtyfour issues Find Element From Element
and the search is scoped to the element’s subtree — except for
By::XPath, see below.
All other variants (Id, Name, Tag, ClassName, Css, Testid,
LinkText, PartialLinkText) are forwarded as CSS selectors, which the
WebDriver spec runs against the element’s descendants only.
§XPath gotcha
XPath //foo is document-rooted, even when called from a
WebElement. To search relative to the element you queried from, use
.//foo:
// Wrong — searches the whole document, may match elements outside `parent`.
let _ = parent.find(By::XPath("//div[@class='child']")).await?;
// Right — searches only inside `parent`.
let _ = parent.find(By::XPath(".//div[@class='child']")).await?;This is W3C WebDriver behaviour, not a thirtyfour quirk — it matches every other Selenium-family client.
Implementations§
Source§impl By
impl By
Sourcepub fn Id(id: impl IntoArcStr) -> By
pub fn Id(id: impl IntoArcStr) -> By
Select element by id.
Sourcepub fn LinkText(text: impl IntoArcStr) -> By
pub fn LinkText(text: impl IntoArcStr) -> By
Select element by link text.
Sourcepub fn PartialLinkText(text: impl IntoArcStr) -> By
pub fn PartialLinkText(text: impl IntoArcStr) -> By
Select element by partial link text.
Sourcepub fn Css(css: impl IntoArcStr) -> By
pub fn Css(css: impl IntoArcStr) -> By
Select element by CSS.
Sourcepub fn XPath(x: impl IntoArcStr) -> By
pub fn XPath(x: impl IntoArcStr) -> By
Select element by XPath.
When called from a WebElement, remember to prefix paths with
.// to scope the search to the element’s subtree — //foo is
document-rooted regardless of which element you query from. See the
By type-level docs for the full explanation.
Sourcepub fn Name(name: impl IntoArcStr) -> By
pub fn Name(name: impl IntoArcStr) -> By
Select element by name.
Sourcepub fn Tag(tag: impl IntoArcStr) -> By
pub fn Tag(tag: impl IntoArcStr) -> By
Select element by tag.
Sourcepub fn ClassName(name: impl IntoArcStr) -> By
pub fn ClassName(name: impl IntoArcStr) -> By
Select element by class.
Sourcepub fn Testid(id: impl IntoArcStr) -> By
pub fn Testid(id: impl IntoArcStr) -> By
Select element by testid.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for By
impl RefUnwindSafe for By
impl Send for By
impl Sync for By
impl Unpin for By
impl UnsafeUnpin for By
impl UnwindSafe for By
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
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> ⓘ
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> ⓘ
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