How can I get selenium to interact with fivethirtyeight search bars?
I am working with this website (https://projects.fivethirtyeight.com/2020-nba-player-projections/) and trying to automate a search of players. I have a list of players but cannot seem to connect to the correct element. I have tried xpath, id, and css_selector. Below is an example code:
driver.get('https://projects.fivethirtyeight.com/2020-nba-player-projections/')
search_bar = driver.find_element_by_id('player-selectbox')
search_bar.click()
search_bar.send_keys('lebron james')
search_bar.send_keys(Keys.RETURN)
Whichever way I try, I get the following error:
Message: element not interactable
Below is a link to a screenshot of the box I'm trying to access.
screenshot
Thanks!
Solution 1:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver.get("https://projects.fivethirtyeight.com/2020-nba-player- projections/")
driver.find_element_by_xpath("//input[@placeholder='player name']").click()
driver.find_element_by_xpath("//input[@placeholder='player name']").send_keys('Kyrie Irving')
driver.find_element_by_xpath("//input[@placeholder='player name']").send_keys(Keys.ARROW_RIGHT)
time.sleep(10)
driver.close()
This code works perfectly, the complexity is that it is an autofill type search bar, I found an easy workaround using Keys.ARROW_RIGHT to take care of it
Attaching screenshot below,