use super::super::Locator;
use super::super::element::BoundingBox;
use crate::error::LocatorError;
impl Locator<'_> {
pub async fn bounding_box(&self) -> Result<Option<BoundingBox>, LocatorError> {
let info = self.query_element_info().await?;
if !info.found {
return Err(LocatorError::NotFound(format!("{:?}", self.selector)));
}
match (info.x, info.y, info.width, info.height) {
(Some(x), Some(y), Some(width), Some(height)) if width > 0.0 && height > 0.0 => {
Ok(Some(BoundingBox {
x,
y,
width,
height,
}))
}
_ => Ok(None),
}
}
}