Reputation: 212
I am trying to get Selenium to do a Youtube search for me and I got to the final step which is actually entering the text and I'm stuck. searchElem uses the id that allows me to use .click(), but I cannot use send_keys() with that id so I tried inputElem and that doesn't work either. There isn't a more specific id or class to use for the search input so I'm not sure what to do. Below is the error I get once I try to use send_keys() with searchElem and inputElem.
selenium.common.exceptions.ElementNotInteractableException: Message: Element <div id="search-input" class="ytd-searchbox-spt"> is not reachable by keyboard
This is my code for the WebDriver and elements within the source code.
driver = webdriver.Firefox()
driver.get('https://www.youtube.com')
searchElem = driver.find_element_by_id('search-input')
inputElem = driver.find_element_by_id('search')
searchElem.click()
searchElem.send_keys('election')
Upvotes: 1
Views: 1949
Reputation: 387
You can create the locator based on search field placeholder (this would make it unique) For example, for english, the placeholder would be "Search" and your locator would look like:
//input[@placeholder='Search']
Upvotes: 0
Reputation: 489
It's possible that 'search'
is the ID of a different element that is being picked up, so try using the xpath
instead.
inputElem = browser.find_element_by_xpath('/html/body/ytd-app/div/div/ytd-masthead/div[3]/div[2]/ytd-searchbox/form/div/div[1]/input')
inputElem.send_keys('election')
Upvotes: 2