Skip to content

Commit

Permalink
Merge pull request #411 from CrendKing/attr
Browse files Browse the repository at this point in the history
Add get_attribute_value() for Element
  • Loading branch information
mdrokz committed Aug 27, 2023
2 parents 775038e + 7b9319d commit 213c7e4
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/browser/tab/element/mod.rs
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 213c7e4

Please sign in to comment.