I'm trying to automate messaging in whatsapp web and on my messages, use some cool emojis, but as you know, chromedriver by default to not type emoji characters with send_keys()
.
So for testing, my code is based on this answer here, which it is working fine, but if I try to send a multiple unicode emoji, this error shows up:
selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: missing command parameters
Sample of my current code:
chatBox = self.driver.find_element_by_class_name('_3uMse')
time.sleep(2)
chatBox.click()
JS_ADD_TEXT_TO_INPUT = """
var elm = arguments[0], txt = arguments[1];
elm.value += txt;
elm.dispatchEvent(new Event('change'));
"""
text = u'\uD83D\uDC6A'
#using this emoji, it works
#text = u'\u263A'
self.driver.execute_script(JS_ADD_TEXT_TO_INPUT, chatBox, text)
chatBox.send_keys(text)
Why is this happening?
Edit 1 - full code with suggested changes to help debbuging
self.driver.get('https://web.whatsapp.com/')
# time to scan qrcode
time.sleep(8)
contact = self.driver.find_element_by_xpath(f"//span[@title='<NAME_OF_SAVED_CONTACT>']")
contact.click()
chatBox = WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CLASS_NAME, "_3uMse")))
chatBox.click()
JS_ADD_TEXT_TO_INPUT = """
var elm = arguments[0], txt = arguments[1];
elm.value += txt;
elm.dispatchEvent(new Event('change'));
"""
text = u'\uD83D\uDC6A'
self.driver.execute_script(JS_ADD_TEXT_TO_INPUT, chatBox, text)
chatBox.send_keys(text)