pub struct Element { /* private fields */ }
Expand description
A single DOM element on the current page.
Note that there is a lot of subtlety in how you can interact with an element through WebDriver, which the WebDriver standard goes into detail on. The same goes for inspecting element state.
Implementations§
Source§impl Element
impl Element
Sourcepub fn from_element_id(client: Client, element_id: ElementRef) -> Self
pub fn from_element_id(client: Client, element_id: ElementRef) -> Self
Construct an Element
with the specified element id.
The element id is the id given by the webdriver.
Sourcepub fn element_id(&self) -> ElementRef
pub fn element_id(&self) -> ElementRef
Get the element id as given by the webdriver.
Source§impl Element
impl Element
Sourcepub async fn enter_frame(&self) -> Result<(), CmdError>
pub async fn enter_frame(&self) -> Result<(), CmdError>
Switches to the frame contained within the element.
See 10.5 Switch To Frame of the WebDriver standard.
Source§impl Element
impl Element
Source§impl Element
impl Element
Sourcepub async fn is_selected(&self) -> Result<bool, CmdError>
pub async fn is_selected(&self) -> Result<bool, CmdError>
Return true if the element is currently selected.
See 13.1 Is Element Selected of the WebDriver standard.
Sourcepub async fn is_enabled(&self) -> Result<bool, CmdError>
pub async fn is_enabled(&self) -> Result<bool, CmdError>
Return true if the element is currently enabled.
See 13.8 Is Element Enabled of the WebDriver standard.
Sourcepub async fn is_displayed(&self) -> Result<bool, CmdError>
pub async fn is_displayed(&self) -> Result<bool, CmdError>
Return true if the element is currently displayed.
See Element Displayedness of the WebDriver standard.
Sourcepub async fn attr(&self, attribute: &str) -> Result<Option<String>, CmdError>
pub async fn attr(&self, attribute: &str) -> Result<Option<String>, CmdError>
Look up an attribute value for this element by name.
Ok(None)
is returned if the element does not have the given attribute.
See 13.2 Get Element Attribute of the WebDriver standard.
Sourcepub async fn prop(&self, prop: &str) -> Result<Option<String>, CmdError>
pub async fn prop(&self, prop: &str) -> Result<Option<String>, CmdError>
Look up a DOM property for this element by name.
Ok(None)
is returned if the element does not have the given property.
Boolean properties such as “checked” will be returned as the String “true” or “false”.
See 13.3 Get Element Property of the WebDriver standard.
Sourcepub async fn css_value(&self, prop: &str) -> Result<String, CmdError>
pub async fn css_value(&self, prop: &str) -> Result<String, CmdError>
Look up the computed value of a CSS property for this element by name.
Ok(String::new())
is returned if the the given CSS property is not found.
See 13.4 Get Element CSS Value of the WebDriver standard.
Sourcepub async fn text(&self) -> Result<String, CmdError>
pub async fn text(&self) -> Result<String, CmdError>
Retrieve the text contents of this element.
See 13.5 Get Element Text of the WebDriver standard.
Sourcepub async fn tag_name(&self) -> Result<String, CmdError>
pub async fn tag_name(&self) -> Result<String, CmdError>
Retrieve the tag name of this element.
See 13.6 Get Element Tag Name of the WebDriver standard.
Sourcepub async fn rectangle(&self) -> Result<(f64, f64, f64, f64), CmdError>
pub async fn rectangle(&self) -> Result<(f64, f64, f64, f64), CmdError>
Gets the x, y, width, and height properties of the current element.
See 13.7 Get Element Rect of the WebDriver standard.
Sourcepub async fn html(&self, inner: bool) -> Result<String, CmdError>
pub async fn html(&self, inner: bool) -> Result<String, CmdError>
Retrieve the HTML contents of this element.
inner
dictates whether the wrapping node’s HTML is excluded or not. For example, take the
HTML:
<div id="foo"><hr /></div>
With inner = true
, <hr />
would be returned. With inner = false
,
<div id="foo"><hr /></div>
would be returned instead.
Source§impl Element
impl Element
Sourcepub async fn click(&self) -> Result<(), CmdError>
pub async fn click(&self) -> Result<(), CmdError>
Simulate the user clicking on this element.
See 14.1 Element Click of the WebDriver standard.
Sourcepub async fn clear(&self) -> Result<(), CmdError>
pub async fn clear(&self) -> Result<(), CmdError>
Clear this element.
See 14.2 Element Clear of the WebDriver standard.
Sourcepub async fn send_keys(&self, text: &str) -> Result<(), CmdError>
pub async fn send_keys(&self, text: &str) -> Result<(), CmdError>
Simulate the user sending keys to this element.
This operation scrolls into view the form control element and then sends the provided keys to the element. In case the element is not keyboard-interactable, an element not interactable error is returned.
See 14.3 Element Send Keys of the WebDriver standard.
Source§impl Element
impl Element
Sourcepub async fn screenshot(&self) -> Result<Vec<u8>, CmdError>
pub async fn screenshot(&self) -> Result<Vec<u8>, CmdError>
Get a PNG-encoded screenshot of this element.
See 19.2 Take Element Screenshot of the WebDriver standard.
Source§impl Element
Higher-level operations.
impl Element
Higher-level operations.
Sourcepub async fn follow(&self) -> Result<(), CmdError>
pub async fn follow(&self) -> Result<(), CmdError>
Follow the href
target of the element matching the given CSS selector without causing a
click interaction.
Sourcepub async fn select_by(&self, locator: Locator<'_>) -> Result<(), CmdError>
pub async fn select_by(&self, locator: Locator<'_>) -> Result<(), CmdError>
Find and click an <option>
child element by a locator.
This method clicks the first <option>
element that is found.
If the element wasn’t found, CmdError::NoSuchElement
will be issued.
Sourcepub async fn select_by_value(&self, value: &str) -> Result<(), CmdError>
pub async fn select_by_value(&self, value: &str) -> Result<(), CmdError>
Find and click an option
child element by its value
attribute.
Sourcepub async fn select_by_index(&self, index: usize) -> Result<(), CmdError>
pub async fn select_by_index(&self, index: usize) -> Result<(), CmdError>
Find and click an <option>
child element by its index.
This method clicks the first <option>
element that is an index
th child
(option:nth-of-type(index+1)
). This will be the index
th <option>
element if the current element is a <select>
. If you use this method on
an Element
that is not a <select>
(such as on a full <form>
), it
may not do what you expect if there are multiple <select>
elements
in the form, or if it there are stray <option>
in the form.
The indexing in this method is 0-based.