python - Selenium 发送密钥在 Ubuntu 上无法使用 /
问题描述
我在 Ubuntu 20.04 上使用 Python 3.6.4 和 Pytest 6.1.1 运行 Selenium,当我运行以下命令发送键时,“/”将从输出中删除。在 Windows 中,它们不会被删除。
element.send_keys("sudo /bin/bash")
最终结果是:sudo binbash
任何想法如何解决这个问题?我试过逃避它们,但没有运气。
谢谢你的时间。
解决方案
我尝试将其编码发送,但没有奏效。
我想出的方法是将值设置到剪贴板并使用 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")
推荐阅读
- c# - .NET Core 工作者服务实体框架上下文
- html - 静态元素之前的 Clearfix 不会阻止浮动
- java - Flutter for Mac 上的 Java 问题
- c++ - 用 shared_ptr 替换 new/delete?
- linux - Ubuntu Linux中是否存在可以使子线程直接读取主线程的cmd参数的系统调用?
- assembly - 为什么使用汇编级语言?和汇编?
- perl - 为 Pushover API 发送帖子时出现“无效参数”消息
- audio - BM20 - 设置为主并将耳机连接到它们
- javascript - 使用 FileReader 上传图像如何获取文件的高度/宽度?
- c++ - 从 char 向量转换为 short 向量和 float 向量