Skip to content

Commit

Permalink
Add get_attribute_value() for Element
Browse files Browse the repository at this point in the history
  • Loading branch information
CrendKing committed Aug 10, 2023
1 parent 775038e commit 7b9319d
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/browser/tab/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,18 @@ impl<'a> Element<'a> {
Ok(description.attributes)
}

pub fn get_attribute_value(&self, attribute_name: &str) -> Result<Option<String>> {
let js_fn = format!("function() {{ return this.getAttribute('{attribute_name}'); }}");

Ok(
if let Some(attribute_value) = self.call_js_fn(&js_fn, Vec::new(), true)?.value {
Some(serde_json::from_value(attribute_value)?)
} else {
None
}
)
}

/// Get boxes for this element
pub fn get_box_model(&self) -> Result<BoxModel> {
let model = self
Expand Down

0 comments on commit 7b9319d

Please sign in to comment.