python - Selenium send_keys 不发送撇号
问题描述
在 Selenium 中,我想输入一个 teststring "hello'world"
,但网页的文本框变为"helloworld"
. 好像撇号不存在一样。替换或拆分字符串也不起作用"'"
。chr(39)
- 我的部分代码:(在python中使用Chrome webdriver)
driver = webdriver.Chrome()
driver.get("https://google.com")
text = "hello'world"
textbox = driver.find_element_by_xpath('//*
[@id="tsf"]/div[2]/div[1]/div[1]/div/div[2]/input')
for i in text:
textbox.send_keys(i)
sleep(0.1)
解决方案
要在Google Home Page的搜索框中发送字符序列 hello'world ,您需要诱导WebDriverWait for the ,您可以使用以下 Locator Strategy:element_to_be_clickable()
使用
CSS_SELECTOR
:from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC driver.get("https://google.com") text = "hello'world" textbox = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.NAME, "q"))) for i in text: textbox.send_keys(i)
浏览器快照:
更新
以前似乎在调用. _ 您可以在以下位置找到一些相关的讨论:send_keys()
此问题已通过 hub 传递到 node 的有效负载的提交修复编码得到解决。
使用Selenium v3.5.3应该可以解决这个问题。
tl; 博士
推荐阅读
- kubernetes-helm - 在 k8s 集群中通过入口公开服务时找不到 404 页面
- javascript - 显示 am4charts.XYChart 中的所有工具提示
- node.js - 使用 node.js 通过 Lambda 将图像上传到 Cloudinary
- couchbase - 更改 couchbase 的日志文件位置
- typing - Microsoft Teams 应用程序,键入指示器持续时间
- rest - 所有父母的组合孩子的 RESTful 命名约定
- php - 根据 WooCommerce 年度订单数更改用户角色
- html - CSS - 无论设备的屏幕大小如何,都将元素定位在同一位置
- python - 弹性搜索。如何将数组传递给搜索模板
- docker - 容器中的 Jenkins 比服务器本身慢得多