1

I'm having trouble with the send_keys(), any help is greatly appreciated.

below is my code

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait


browser = webdriver.Chrome('C:\\Users\johns\Downloads\chromedriver')
browser.get('https://www.youtube.com/')

searchbox=browser.find_element_by_xpath('//*[@id="search"]')
searchbox.send_keys('economics explained')

searchbutton = WebDriverWait(browser, 6).until(EC.presence_of_element_located((By.XPATH, '//*[@id="search-icon-legacy"]/yt-icon')))
browser.execute_script("arguments[0].click();", searchbutton)

Every time I run the program, the chrome tab pops up and youtube is opened but searchbox.send_keys('economics explained') doesn't work instead, I get this error message.

File "C:/Users/johns/PycharmProjects/DABIGHIT/testing 2.py", 
line 11, in <module> searchbox.send_keys('economics explained')

File "C:\Users\johns\PycharmProjects\DABIGHIT\venv\lib\site-packages\selenium\webdriver\remote
\webelement.py", 
line 477, in send_keys self._execute(Command.SEND_KEYS_TO_ELEMENT),

File "C:\Users\johns\PycharmProjects\DABIGHIT\venv\lib\site-packages\selenium\webdriver\remote
\webelement.py",
line 633, in _execute return self._parent.execute(command, params)

File "C:\Users\johns\PycharmProjects\DABIGHIT\venv\lib\site-packages\selenium\webdriver\remote
\webdriver.py", 
line 321, in execute self.error_handler.check_response(response)

File "C:\Users\johns\PycharmProjects\DABIGHIT\venv\lib\site-packages\selenium\webdriver\remote
\errorhandler.py", 
line 242, in check_response raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable

1 Answer 1

1

ElementNotInteractableException is occured when an element is found, but you can not interact with it.

There are so many reasons of it:

element is not visible / not displayed element is off screen element is behind another element or hidden

You can try below solution:

driver = webdriver.Chrome(executable_path=" path for chromedriver.exe")
url = 'http://www.youtube.com'
driver.get(url)
driver.maximize_window()
wait = WebDriverWait(driver, 20)
print(driver.title)

element = wait.until(EC.presence_of_element_located((By.XPATH, "//form[@id='search-form']//div[@id='container']//div[@id='search-input']//input[@id='search']")))

actionChains = ActionChains(driver)
actionChains.move_to_element(element).click().perform()
actionChains.move_to_element(element).send_keys("Test",Keys.RETURN).perform()

driver.maximize_window()

Note : please add below imports to your solution

from selenium import webdriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
Sign up to request clarification or add additional context in comments.

1 Comment

Great!!! would you kind enough to accept answer and hit upvote button from your end.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.