Chromiumoxide input Chinese, run error

I try to use the crate chromiumoxide to control the browser, when i input English param it works well, but it fails when input Chinese.

let page = browser.new_page("https://www.baidu.cn/").await?;
    let search_element = page.find_element(".input-search").await?;

	search_element.click().await?;
	let search_list_page  = search_element.type_str("你好").await?.press_key("Enter").await?;

and the result

the input-search element Element { remote_object_id: RemoteObjectId("3845533832273583898.3.3"), backend_node_id: BackendNodeId(14), node_id: NodeId(53), tab: PageInner { target_id: TargetId("8DA88B329BD1447D2B1DBFC65C662A05"), session_id: SessionId("F647E3A0998EA882055908E7BF676062"), sender: Sender { closed: false } } }
Error: ChromeMessage("Key not found: 你")
error: process didn't exit successfully

is there any person who uses the crate? And how to resolve it? Thanks a lot.

Here's the source of the method you're ultimately calling:

/// This simulates pressing keys on the page.
    ///
    /// # Note The `input` is treated as series of `KeyDefinition`s, where each
    /// char is inserted as a separate keystroke. So sending
    /// `page.type_str("Enter")` will be processed as a series of single
    /// keystrokes:  `["E", "n", "t", "e", "r"]`. To simulate pressing the
    /// actual Enter key instead use `page.press_key(
    /// keys::get_key_definition("Enter").unwrap())`.
    pub async fn type_str(&self, input: impl AsRef<str>) -> Result<&Self> {
        for c in input.as_ref().split("").filter(|s| !s.is_empty()) {
            self.press_key(c).await?;
        }
        Ok(self)
    }

Basically this means that what you need to put into type_str are the keystrokes, not the composite characters. I know this is not the best UX for languages that depend so much on composition when typing, but that's how the API works when you are replicating the exact behaviour as when typing on your keyboard.

4 Likes