selenium.common.exceptions.elementnotinteractiableexception:Message:Element<g id=“search”>无法通过键盘访问

2024-04-25 14:05:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我写了一个自动化程序,打开youtube,输入chillhop,然后让自动化点击搜索。当我运行脚本时,它只打开我的浏览器并打开youtube,然后我得到一个错误程序停止在这里是错误:

Traceback (most recent call last):
  File "automation.py", line 13, in <module>
    searchbox.send_keys('chillhop')
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <g id="search"> is not reachable by keyboard

这是我输入的代码:

from selenium import webdriver

#varible of drive to run open up the firefox browser
driver = webdriver.Firefox()

#open this website
driver.get('https://youtube.com')

#create a varible to store the xpath of the search bar on youtube
searchbox = driver.find_element_by_xpath('//*[@id="search"]')

#to type in the search box
searchbox.send_keys('chillhop')

#click the search button
searchbutton = driver.find_element_by_xpath('//*[@id="search-icon-legacy"]')
searchbutton.click()

Tags: theinpysearchyoutubelibpackagesusr