I am trying to create a bot to get data from CoinGecho. It will enter my keywords and do the other stuff.
However, it respond with the "element not interactable" everytime I attempt to send the keys. Here is my code snippet:
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get('https://www.coingecko.com/')
driver.implicitly_wait(5)
# locate text input field
p = driver.find_element(By.XPATH,'//*[@id="search-input-field"]')
# click text input field. **Button.click will result in "elment not interactable" error, so I have used js method.**
driver.execute_script("arguments[0].click", p)
# send key words
p.send_keys('usdt')
Result: selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
I also tried to click the "search bar" before clicking the text input field, but still have the same error:
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get('https://www.coingecko.com/')
driver.implicitly_wait(5)
# locate "search bar"
p1 = driver.find_element(By.XPATH,'//*[@id="search-bar"]')
# click search bar
driver.execute_script("arguments[0].click", p1)
#locate text input field
p2 = driver.find_element(By.XPATH,'//*[@id="search-input-field"]')
driver.execute_script("arguments[0].click", p2)
# send key words
p2.send_keys('usdt')
Result: same error
I had a feeling that I am not locating the correct elements. Anyone has some ideas? Thanks in advance.
I expect that the bot will be able to send the keys succesfully.
That xpath match 2 elements, you want second one, first is hidden.
Change your XPATH to this one:
'//div[not(.//div[@class="tw-hidden"])]//div[@id="search-bar"]'
Your Code
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
driver = webdriver.Chrome()
driver.get('https://www.coingecko.com/')
driver.implicitly_wait(5)
#locate text input field
p2 = driver.find_element(By.XPATH,'//div[not(.//div[@class="tw-hidden"])]//div[@id="search-bar"]')
driver.execute_script("arguments[0].click", p2)
#or just -> p2.click()
# send key words
p2.send_keys('usdt')