gpt4 book ai didi

python - Selenium send_keys 不发送撇号

转载 作者:行者123 更新时间:2023-12-02 00:06:48 25 4
gpt4 key购买 nike

在Selenium中我想输入一个测试字符串“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)
  • 浏览器截图: Browser screenshot

最佳答案

要在Google 主页的搜索框中发送字符序列 hello'world,您需要引发WebDriverWait em> 对于 element_to_be_clickable() ,您可以使用以下 Locator Strategy :

  • 使用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)
  • 浏览器快照:

apostrophe

<小时/>

更新

之前在调用 send_keys() 时,非美国键盘设置Unicode 字符似乎存在一些问题。您可以在以下位置找到一些相关讨论:

此问题已通过提交 Fixing encoding of payload passed by hub to a node 解决.

使用Selenium v​​3.5.3应该可以解决这个问题。

<小时/>

tl;博士

Change your keyboard layout

关于python - Selenium send_keys 不发送撇号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59993665/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com