首页 > 解决方案 > Selenium 发送密钥在 Ubuntu 上无法使用 /

问题描述

我在 Ubuntu 20.04 上使用 Python 3.6.4 和 Pytest 6.1.1 运行 Selenium,当我运行以下命令发送键时,“/”将从输出中删除。在 Windows 中,它们不会被删除。

element.send_keys("sudo /bin/bash")

最终结果是:sudo binbash

任何想法如何解决这个问题?我试过逃避它们,但没有运气。

谢谢你的时间。

标签: pythonlinuxseleniumubuntusendkeys

解决方案


我尝试将其编码发送,但没有奏效。

我想出的方法是将值设置到剪贴板并使用 Ctrl + V 将其粘贴到字段中。

from subprocess import PIPE, Popen        

p = Popen(["xsel", "-bi"], stdin=PIPE)
p.communicate(input=str.encode(text.strip()))
        
text_area = component.find_element_by_tag_name("textarea")
text_area.send_keys(Keys.CONTROL, "v")

推荐阅读