Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python selenium send_keys emoticons characters

I need send emoticons with selenium, for example:

���������✊🏿�🏿�🏿�🏼�🏻�����

and selenium returns an error, I tested with .send_keys(unicode(bio_text, 'ascii')) # iso-8859-1, the same result.

How can I send these characters with python selenium?

python code:

driver.find_element_by_id("biography").clear()
driver.find_element_by_id("biography").send_keys(unicode('���������✊🏿�🏿�🏿�🏼�🏻�����', 'ascii'))  # iso-8859-1

emoticons example :

���������✊🏿�🏿�🏿�🏼�🏻�����
like image 324
seoexpert Avatar asked Jan 08 '16 15:01

seoexpert


1 Answers

Here is what i did.

# -*- coding: utf-8 -*-
from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://google.com')

text = u"😀😁'😂'😇😺"
text = text.replace("'", "\\'")  # escape single quotes
text = text.encode('utf-8')  # needed to make format function work

driver.execute_script(
    "document.getElementById('lst-ib').value = '{data}'".format(
        data=text
    ))
like image 191
Nikita Avatar answered Oct 11 '22 12:10

Nikita