0

I am trying to sendkeys an emoji. I have tried to send it by copying the emoji , but it raised this exception:

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

I tried to send it as unicode but without any success. It isn't the intended sign.

input.SendKeys("/u1F44D")

What is the proper way to send an emoji?

Searched and found this but it does not have an answer therefore I'm asking again.

JeffC
  • 22,180
  • 5
  • 32
  • 55
Shahar Azar
  • 89
  • 3
  • 9

3 Answers3

2

The issue is that you’re using ChromeDriver. As the exception message states, ChromeDriver only supports code points in the Unicode Basic Multilingual Plane at present. If you were to use another driver, say, FirefoxDriver or InternetExplorerDriver, sending the emoji would have better results. There are specific tests in the Web Platform Test suite that specifically send emojis, and these work for other browsers.

Incidentally, the correct way to send the character in C# would be

input.SendKeys("\u1F44D");
JimEvans
  • 27,201
  • 7
  • 83
  • 108
2

You can achieve this in C# with Selenium using the IJavaScriptExecutor

using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace ResearchDevelopment
{
    internal class Program
    {  
        static void Main(string[] args)
        {
            var driver = new ChromeDriver() { Url = "http://www.google.co.za" };

            var searchInput = driver.FindElement(By.XPath("//input[@aria-label='Search']"));

            PopulateElementJs(driver, searchInput, "");

            searchInput.SendKeys(Keys.Enter); // Optional

            driver?.Quit();
        }

        public static void PopulateElementJs(IWebDriver driver, IWebElement element, string text)
        {
            var script = "arguments[0].value=' " + text + " ';";
            ((IJavaScriptExecutor)driver).ExecuteScript(script, element);
        }
    }
}

packages.config

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Selenium.Chrome.WebDriver" version="76.0.0" targetFramework="net472" />
  <package id="Selenium.Support" version="3.0.0" targetFramework="net472" />
  <package id="Selenium.WebDriver" version="3.0.0" targetFramework="net472" />
</packages>
1

Hello Vibhav Ramcharan

I did a first test, on the Google search box it works! I did a second test to write on the modal window of a facebook group, but nothing happens!

From your example I have only replaced:

var searchInput = driver.FindElement(By.XPath("//input[@aria-label='Search']"));

with:

var searchInput = driver.FindElement(By.XPath("//div[@class='rq0escxv datstx6m k4urcfbm a8c37x1j']/div/div/div/div/div/div/span"));

The final is where we go to write the Post

If I use plain text without emoji, the method below works.

driver.FindElement(By.XPath("//div[@class='rq0escxv datstx6m k4urcfbm a8c37x1j']/div/div/div/div/div/div/span")).SendKeys("...My text of the post...");

Maybe I need to change this?

var script = "arguments[0].value='" + text + "';";
w_t
  • 41
  • 5