Starting to code, so everything is new to me. Been Trying to get this code to work but keep running into errors. I try adding some type of delay since i seen that it might that website doesn't load in time but that does not work.
Code:
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.youtube.com/')
time. sleep(5)
searchbox = driver.find_element("xpath", '//*[@id="search"]')
time. sleep(5)
searchbox.send_keys('Ludwig')
time. sleep(5)
searchButton = driver.find_element("xpath", '//*[@id="search-icon-legacy"]')
searchButton.click()
ERORR:
[WDM] - ====== WebDriver manager ======
[WDM] - Current google-chrome version is 103.0.5060
[WDM] - Get LATEST chromedriver version for 103.0.5060 google-chrome
[WDM] - Driver [C:\Users\regra\.wdm\drivers\chromedriver\win32\103.0.5060.53\chromedriver.exe] found in cache
Warning (from warnings module):
File "C:\Users\regra\Downloads\WebAutomationPython-master\WebAutomationPython-master\automation.py", line 5
driver = webdriver.Chrome(ChromeDriverManager().install())
DeprecationWarning: executable_path has been deprecated, please pass in a Service object
Traceback (most recent call last):
File "C:\Users\regra\Downloads\WebAutomationPython-master\WebAutomationPython-master\automation.py", line 10, in <module>
searchbox.send_keys('Ludwig')
File "C:\Users\regra\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 223, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\regra\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 396, in _execute
return self._parent.execute(command, params)
File "C:\Users\regra\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 435, in execute
self.error_handler.check_response(response)
File "C:\Users\regra\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=103.0.5060.66)
Stacktrace:
Backtrace:
Ordinal0 [0x00FE6463 2188387]
Ordinal0 [0x00F7E461 1762401]
Ordinal0 [0x00E93C40 801856]
Ordinal0 [0x00EBCF63 970595]
Ordinal0 [0x00EBC63E 968254]
Ordinal0 [0x00EDC7DC 1099740]
Ordinal0 [0x00EB7FF4 950260]
Ordinal0 [0x00EDC9F4 1100276]
Ordinal0 [0x00EECC22 1166370]
Ordinal0 [0x00EDC5F6 1099254]
Ordinal0 [0x00EB6BE0 945120]
Ordinal0 [0x00EB7AD6 948950]
GetHandleVerifier [0x012871F2 2712546]
GetHandleVerifier [0x0127886D 2652765]
GetHandleVerifier [0x0107002A 520730]
GetHandleVerifier [0x0106EE06 516086]
Ordinal0 [0x00F8468B 1787531]
Ordinal0 [0x00F88E88 1805960]
Ordinal0 [0x00F88F75 1806197]
Ordinal0 [0x00F91DF1 1842673]
BaseThreadInitThunk [0x76FFFA29 25]
RtlGetAppContainerNamedObjectPath [0x771E7A9E 286]
RtlGetAppContainerNamedObjectPath [0x771E7A6E 238]
ANY HELP WILL BE MUCH APPRECIATED
CodePudding user response:
There are 5 elements match your locator, and webdriver tries to send keys to the first one that is actually not interactable. Fix locator, replace:
searchbox = driver.find_element("xpath", '//*[@id="search"]')
with
searchbox = driver.find_element("xpath", '//input[@id="search"]')