OpenQA.Selenium.WebDriverException: 'unknown error: ChromeDriver only supports characters in the BMP while sending an emoji through C# Selenium

前端 未结 2 982
暖寄归人
暖寄归人 2020-12-12 06:57

I am trying to sendkeys a emoji.I have tried to send it by coping the signal

相关标签:
2条回答
  • 2020-12-12 07:36

    This error message...

    OpenQA.Selenium.WebDriverException: 'unknown error: ChromeDriver only supports characters in the BMP
    

    ...implies that the ChromeDriver was unable to send the emoji i.e. ?? signal through SendKeys() method.

    Taking out a leaf from @JimEvans answer, currently ChromeDriver only supports code points in the Plane 0 i.e. the Basic Multilingual Plane (BMP) at present.

    Using GeckoDriver/Firefox or IEDriverServer/IE combo would have fetched you better results.

    You can find the current status of the specific tests in the Web Platform Test Suite that specifically send emojis and these work for other browsers too.

    However, to send a emoji through C# you can use the following syntax:

    input.SendKeys("\u1F44D");
    
    0 讨论(0)
  • 2020-12-12 07:40

    Solution

        async sendKeysWithEmojis(element, text) {
            const script = `var elm = arguments[0],
            txt = arguments[1];elm.value += txt;
            elm.dispatchEvent(new Event('keydown', {bubbles: true}));
            elm.dispatchEvent(new Event('keypress', {bubbles: true}));
            elm.dispatchEvent(new Event('input', {bubbles: true}));
            elm.dispatchEvent(new Event('keyup', {bubbles: true}));`;
            await this.driver.executeScript(script, element, text);
        }
    

    Call it like so

    const element = await this.driver.findElement(selector);
    await sendKeysWithEmojis(element, '                                                                    
    0 讨论(0)
提交回复
热议问题