Search code examples
pythonseleniumgoogle-chromeselenium-chromedriveremoji

Chromedriver only supports characters in the BMP error while sending Emoji with ChromeDriver Chrome using Selenium Python to Tkinter's label() textbox


I am automating whatsapp messages and would like to send them out through a tkinter window. In this tkinter window I have created a message box with the help of .label() and I am able to connect to whatsapp web through selenium.

Currently, I am able to send out messages already, but without emojis. When I include emojis, I get this error "Chromedriver only supports characters in the BMP". How can I include emojis?


Solution

  • This works (tested at 2023-12-25)

    from selenium import webdriver
    
    JS_ADD_TEXT_TO_INPUT = """
      var elm = arguments[0], txt = arguments[1];
      elm.value += txt;
      elm.dispatchEvent(new Event('change'));
      """
    
    browser = webdriver.Chrome('C:\\Python37\\chromedriver.exe')
    
    browser.get("https://google.com/")
    elem = browser.find_element("xpath", "//textarea[@name='q']")
    
    text = "🌎 🌊 " + u'\u2764'
    
    browser.execute_script(JS_ADD_TEXT_TO_INPUT, elem, text)
    

    enter image description here