I tried Most of the solution of StackOverflow but didn’t work for me I am trying to send some course name to youtube search bar using selenium python it works fine before but now it gives this error while doing this And search_bar.send_keys(course_name) works fine for other websites but not in YT
Traceback (most recent call last): File "src/gevent/greenlet.py", line 766, in gevent._greenlet.Greenlet.run File "/home/sh4d0w/PycharmProjects/AutoMate/venv/lib/python3.7/site-packages/eel/__init__.py", line 257, in _process_message return_val = _exposed_functions[message['name']](*message['args']) File "/home/sh4d0w/PycharmProjects/AutoMate/SmallTalk.py", line 72, in SingleQueryinputValue RecommendCourse.getUdacityCourse(str(val)) File "/home/sh4d0w/PycharmProjects/AutoMate/RecommendCourse.py", line 160, in getUdacityCourse getYoutubeCourse(course_name, driver) File "/home/sh4d0w/PycharmProjects/AutoMate/RecommendCourse.py", line 98, in getYoutubeCourse search_bar.send_keys(course_name) File "/home/sh4d0w/PycharmProjects/AutoMate/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys 'value': keys_to_typing(value)}) File "/home/sh4d0w/PycharmProjects/AutoMate/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute return self._parent.execute(command, params) File "/home/sh4d0w/PycharmProjects/AutoMate/venv/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute self.error_handler.check_response(response) File "/home/sh4d0w/PycharmProjects/AutoMate/venv/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 not interactable (Session info: chrome=81.0.4044.129) 2020-04-29T08:00:02Z <Greenlet at 0x7fd2089c67b8: _process_message({'call': 2.1877049007713376, 'name': 'SingleQueryi, <geventwebsocket.websocket.WebSocket object at 0x7)> failed with ElementNotInteractableException
Code sample
option = webdriver.ChromeOptions() option.add_argument("window-size=1200x600"); driver = webdriver.Chrome('/usr/bin/chromedriver', options=option) driver.get("https://www.youtube.com") getYoutubeCourse(course_name, driver)
getYoutubeCourse() function body
def getYoutubeCourse(course_name, driver): time.sleep(2) search_bar = driver.find_element_by_xpath('//*[@id="search"]') search_bar.send_keys(course_name) search_bar_button = WebDriverWait(driver, 5).until(EC.element_to_be_clickable( (By.XPATH, '//*[@id="search-icon-legacy"]'))) search_bar_button.click() ......
then after this, the logic of scraping the youtube links is there I also tried web driver wait and all, and my drivers are also up to date
Please help I am new in python and selenium
Advertisement
Answer
There is 3 elements found by xpath : //*[@id="search"]
You have to correct it to
//input[@id="search"]