python selenium send_keys表情字符

标签 python selenium selenium-webdriver

我需要用selenium发送表情,例如:

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

selenium 返回错误,我用 .send_keys(unicode(bio_text, 'ascii')) # iso-8859-1 测试,结果相同。

如何使用 python selenium 发送这些字符?

python 代码:

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

表情符号示例:

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

最佳答案

这是我做的。

# -*- 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
    ))

关于python selenium send_keys表情字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34680238/

相关文章:

selenium - capybara firefox 48 出现错误

java - 如何将输出添加到 xpath

python-3.x - Selenium 3 Firefox .click() 不工作

python - 如何在 Python 3 中将 SubElement 的内容包装在 XML 标记中?

python - 在mod_python下执行模块时出现ImportError

Python 和 Py2Exe : "%1 Is Not A Valid Win32 Application"

python - 关于 python 类 __init__ 和装饰器

docker - 为什么我无法从我的 GitLab 作业连接到 selenium docker-compose 服务?

java - 具有失败的配置:@BeforeClass setUp和失败的配置:@AfterClass tearDown java.lang.NullPointerException错误

java - native 事件在带有 selenium 的不同版本的 Firefox 上表现不同