Struct chromiumoxide_fork::element::Element
source · pub struct Element {
pub remote_object_id: RemoteObjectId,
pub backend_node_id: BackendNodeId,
pub node_id: NodeId,
/* private fields */
}
Expand description
Represents a DOM Element.
Fields§
§remote_object_id: RemoteObjectId
The Unique object identifier
backend_node_id: BackendNodeId
Identifier of the backend node.
node_id: NodeId
The identifier of the node this element represents.
Implementations§
source§impl Element
impl Element
sourcepub async fn find_element(&self, selector: impl Into<String>) -> Result<Self>
pub async fn find_element(&self, selector: impl Into<String>) -> Result<Self>
Returns the first element in the document which matches the given CSS selector.
sourcepub async fn find_elements(
&self,
selector: impl Into<String>
) -> Result<Vec<Element>>
pub async fn find_elements( &self, selector: impl Into<String> ) -> Result<Vec<Element>>
Return all Element
s in the document that match the given selector
sourcepub async fn bounding_box(&self) -> Result<BoundingBox>
pub async fn bounding_box(&self) -> Result<BoundingBox>
Returns the bounding box of the element (relative to the main frame)
sourcepub async fn clickable_point(&self) -> Result<Point>
pub async fn clickable_point(&self) -> Result<Point>
Returns the best Point
of this node to execute a click on.
sourcepub async fn call_js_fn(
&self,
function_declaration: impl Into<String>,
await_promise: bool
) -> Result<CallFunctionOnReturns>
pub async fn call_js_fn( &self, function_declaration: impl Into<String>, await_promise: bool ) -> Result<CallFunctionOnReturns>
Submits a javascript function to the page and returns the evaluated result
Example get the element as JSON object
let js_fn = "function() { return this; }";
let element_json = element.call_js_fn(js_fn, false).await?;
Execute an async javascript function
let js_fn = "async function() { return this; }";
let element_json = element.call_js_fn(js_fn, true).await?;
sourcepub async fn json_value(&self) -> Result<Value>
pub async fn json_value(&self) -> Result<Value>
Returns a JSON representation of this element.
sourcepub async fn hover(&self) -> Result<&Self>
pub async fn hover(&self) -> Result<&Self>
Scrolls the element into view and uses a mouse event to move the mouse over the center of this element.
sourcepub async fn scroll_into_view(&self) -> Result<&Self>
pub async fn scroll_into_view(&self) -> Result<&Self>
Scrolls the element into view.
Fails if the element’s node is not a HTML element or is detached from the document
sourcepub async fn click(&self) -> Result<&Self>
pub async fn click(&self) -> Result<&Self>
This focuses the element by click on it
Bear in mind that if click()
triggers a navigation this element may be
not exist anymore.
sourcepub async fn type_str(&self, input: impl AsRef<str>) -> Result<&Self>
pub async fn type_str(&self, input: impl AsRef<str>) -> Result<&Self>
Type the input
Example type text into an input element
let element = page.find_element("input#searchInput").await?;
element.click().await?.type_str("this goes into the input field").await?;
sourcepub async fn press_key(&self, key: impl AsRef<str>) -> Result<&Self>
pub async fn press_key(&self, key: impl AsRef<str>) -> Result<&Self>
Presses the key.
Example type text into an input element and hit enter
let element = page.find_element("input#searchInput").await?;
element.click().await?.type_str("this goes into the input field").await?
.press_key("Enter").await?;
sourcepub async fn description(&self) -> Result<Node>
pub async fn description(&self) -> Result<Node>
The description of the element’s node
sourcepub async fn attributes(&self) -> Result<Vec<String>>
pub async fn attributes(&self) -> Result<Vec<String>>
Attributes of the Element
node in the form of flat array `[name1,
value1, name2, value2]
sourcepub async fn attribute(
&self,
attribute: impl AsRef<str>
) -> Result<Option<String>>
pub async fn attribute( &self, attribute: impl AsRef<str> ) -> Result<Option<String>>
Returns the value of the element’s attribute
sourcepub async fn iter_attributes(
&self
) -> Result<impl Stream<Item = (String, Result<Option<String>>)> + '_>
pub async fn iter_attributes( &self ) -> Result<impl Stream<Item = (String, Result<Option<String>>)> + '_>
A Stream
over all attributes and their values
sourcepub async fn inner_text(&self) -> Result<Option<String>>
pub async fn inner_text(&self) -> Result<Option<String>>
The inner text of this element.
sourcepub async fn inner_html(&self) -> Result<Option<String>>
pub async fn inner_html(&self) -> Result<Option<String>>
The inner HTML of this element.
sourcepub async fn outer_html(&self) -> Result<Option<String>>
pub async fn outer_html(&self) -> Result<Option<String>>
The outer HTML of this element.
sourcepub async fn string_property(
&self,
property: impl AsRef<str>
) -> Result<Option<String>>
pub async fn string_property( &self, property: impl AsRef<str> ) -> Result<Option<String>>
Returns the string property of the element.
If the property is an empty String, None
is returned.
sourcepub async fn property(&self, property: impl AsRef<str>) -> Result<Option<Value>>
pub async fn property(&self, property: impl AsRef<str>) -> Result<Option<Value>>
Returns the javascript property
of this element where property
is
the name of the requested property of this element.
See also Element::inner_html
.
sourcepub async fn properties(&self) -> Result<HashMap<String, PropertyDescriptor>>
pub async fn properties(&self) -> Result<HashMap<String, PropertyDescriptor>>
Returns a map with all PropertyDescriptor
s of this element keyed by
their names
sourcepub async fn screenshot(
&self,
format: CaptureScreenshotFormat
) -> Result<Vec<u8>>
pub async fn screenshot( &self, format: CaptureScreenshotFormat ) -> Result<Vec<u8>>
Scrolls the element into and takes a screenshot of it
sourcepub async fn save_screenshot(
&self,
format: CaptureScreenshotFormat,
output: impl AsRef<Path>
) -> Result<Vec<u8>>
pub async fn save_screenshot( &self, format: CaptureScreenshotFormat, output: impl AsRef<Path> ) -> Result<Vec<u8>>
Save a screenshot of the element and write it to output