sumdub
sumdub

Reputation: 31

Python - selenium gets error: Message: Element <g id="search"> is not reachable by keyboard

The target url launches fine, but I'm unable to figure out why it's not entering the sample text, "text".

code:

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://www.youtube.com/")

searchbox = driver.find_element_by_xpath('//*[@id="search"]')
searchbox.send_keys("test")

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

error:

Traceback (most recent call last):
  File "/Users/MacBook/Desktop/selenium_test.py", line 7, in <module>
    searchbox.send_keys("test")
  File "/Applications/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
    'value': keys_to_typing(value)})
  File "/Applications/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
    return self._parent.execute(command, params)
  File "/Applications/anaconda3/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Applications/anaconda3/lib/python3.7/site-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

Thanks in advance.

Upvotes: 3

Views: 464

Answers (1)

Zack Henkusens
Zack Henkusens

Reputation: 160

Full Solution:

#Type text into search box and hit search button on youtube   

from selenium import webdriver

driver = webdriver.Firefox() 
driver.get("https://www.youtube.com/")

## Changed ##
searchbox = driver.find_element_by_xpath('//input[@id="search"]')
#####
searchbox.send_keys("test")

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

Result: enter image description here

The only problem was the line:

searchbox = driver.find_element_by_xpath('//*[@id="search"]')

Should have been set as an input element, otherwise seems to find an invalid element.

Upvotes: 2

Related Questions