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

2

0

I am trying to sendkeys a emoji.I have tried to send it by coping the signal πŸ‘, but it raised this exception.

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

Than i tried to send it as unicode, but without any success. its ain't the deisrable sign.

input.SendKeys("/u1F44D")

What is the proper way to send an emoji ?

Epileptic answered 20/5, 2018 at 20:45 Comment(0)
H
0

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");
Hauteur answered 17/12, 2018 at 8:0 Comment(3)
Hope Chrome Driver will fix this soon – Ludwig
@Kostas Hope so – Hauteur
Hi! Any update you know about? I had ran into the same issue just recently. The solution was IJavaScriptExecutor.ExecuteScript(script, args) but thanks to angular and ag-grid, it is followed by a slightly dark magic... :D – Vergara
S
0

Solution in Javascript code

    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, 'πŸš€πŸ˜€ This one shall pass πŸš€πŸ˜€');

What is happening here? We are emulating native key presses using events

Notice that the {bubbles: true} is optional (Was needed in my case due to a complex wrapped input)

Spew answered 2/3, 2020 at 8:51 Comment(4)
Care to convert it to c#? – Born
Haven't written in c# for years - but the above code should give you direction – Spew
I tried it but I get "unexpeted error" on "this.driver.findElement". the code doesn't recognize it. – Born
Perhaps something like (Replace selector below): var driver = new ChromeDriver() { Url = "http://www.something.com" }; var element = driver.FindElement(By.XPath("//input[@aria-label='Search']")); PopulateElementJs(driver, searchInput, "πŸ––"); Also make sure you have this function public static void PopulateElementJs(IWebDriver driver, IWebElement element, string text) { var script = "arguments[0].value=' " + text + " ';"; ((IJavaScriptExecutor)driver).ExecuteScript(script, element); } – Spew

© 2022 - 2024 β€” McMap. All rights reserved.