【问题标题】:sendkeys of selenium in python dose not work [duplicate]python中硒的sendkeys不起作用[重复]
【发布时间】:2018-08-02 02:42:01
【问题描述】:

我有这个代码:

from selenium import webdriver
#open Firefox
driver=webdriver.Firefox()
#open arbitrary ur
url="https://www.scopus.com/search/form.uri?display=basic"
driver.get(url)
#click on input  element for writing special word
search=driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/label""")
search.click()
driver.implicitly_wait(5)
#write your special word
search.send_keys("internet of things")
driver.implicitly_wait(5)
search.submit()

错误堆栈跟踪:

raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <label class="inputTextLabel activeInputLabel"> is not reachable by keyboard

url 已打开,x-path 已识别,但 send_keys 不起作用。我该怎么办?

【问题讨论】:

  • 网页中没有带有id="txtBoxSearch"的元素..
  • 您必须订阅才能访问该网址。
  • 这无助于回答你
  • 我认为你的引号太多了:find_element_by_xpath("""//*[@id="txtBoxSearch"]/label""")。我建议你买这个:find_element_by_xpath("//*[@id='txtBoxSearch']/label")
  • 100% 正确。

标签: python-2.7 xpath selenium-webdriver web-scraping sendkeys


【解决方案1】:

label 节点只是输入字段的“名称”,您不能向该元素发送键。您需要改为处理文本input 节点。

假设 HTML 看起来像

<div id='txtBoxSearch'>
    <label>Search</label>
    <input type='text'>
</div>

你可以试试

search = driver.find_element_by_xpath("""//*[@id="txtBoxSearch"]/input[@type="text"]""")

【讨论】:

    猜你喜欢
    • 2023-01-28
    • 1970-01-01
    • 1970-01-01
    • 2017-08-06
    • 1970-01-01
    • 2019-10-13
    • 2018-12-15
    • 2016-08-31
    • 2019-07-19
    相关资源
    最近更新 更多