Vrtgs / thirtyfour

Selenium WebDriver client for Rust, for automated testing of websites
Other
1.02k stars 72 forks source link

Get prop `naturalWidth` of img, get a error ` Json("Unexpected value for property: Number(450)")` #233

Open wccyzxy opened 2 months ago

wccyzxy commented 2 months ago

The code to get prop naturalWidth of img element:

let question_img = question_img_div.find(By::Css("img")).await?;
let origin_width= question_img.prop("naturalWidth").await?;

The error is:

Error: Json("Unexpected value for property: Number(450)")

Goto the code of prop function:

    pub async fn prop(&self, name: impl Into<String>) -> WebDriverResult<Option<String>> {
        let resp = self
            .handle
            .cmd(Command::GetElementProperty(self.element_id.clone(), name.into()))
            .await?;
        match resp.value()? {
            Value::String(v) => Ok(Some(v)),
            Value::Bool(b) => Ok(Some(b.to_string())),
            Value::Null => Ok(None),
            v => Err(WebDriverError::Json(format!("Unexpected value for property: {:?}", v))),
        }
    }

It's not consider Number type. It's a bug? or the way to use is not correct?