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 ?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
delex
  • 201
  • 1
  • 5
  • 13

2 Answers2

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");
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
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)

Gal Bracha
  • 19,004
  • 11
  • 72
  • 86
  • Care to convert it to c#? – Dohab Jul 10 '22 at 21:16
  • Haven't written in c# for years - but the above code should give you direction – Gal Bracha Jul 11 '22 at 08:24
  • I tried it but I get "unexpeted error" on "this.driver.findElement". the code doesn't recognize it. – Dohab Jul 11 '22 at 13:03
  • 1
    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); } ` – Gal Bracha Jul 12 '22 at 09:26