Home > OS >  Selenium returning "Message: element not interactable" when trying to place text
Selenium returning "Message: element not interactable" when trying to place text

Time:11-12

Ive been attempting to use selenium to go through elements on soundclouds website and am having trouble interacting with the input tags. When I try to write in the input tag of the class "headerSearch__input" with the send keys command, I get back the error "Message: element not interactable". May someone please explain to me what im doing wrong?

from tkinter import *
import random
import urllib.request
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import requests
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options



driver = webdriver.Chrome(executable_path='/Users/quanahbennett/PycharmProjects/SeleniumTest/chromedriver')
url= "https://soundcloud.com/"
driver.get(url)
#time.sleep(30)

wait = WebDriverWait(driver, 30)
#link = driver.find_elements_by_link_text("Sign in")
#link[0].click()
#driver.execute_script("arguments[0].click();", link[0]) 


#SUCCESFUL LOGIN BUTTON PUSH
#please = driver.find_element_by_css_selector('button.frontHero__loginButton')
#please.click()

attempt = driver.find_element_by_css_selector('input.headerSearch__input')
time.sleep(10)
attempt.send_keys('Hello')


breakpoint()





#driver.quit()

CodePudding user response:

The locator - input.headerSearch__input is highlighting two different elements in the DOM. Its important to find unique locators. Link to refer

And also close the cookie pop-up. And then try to interact with elements.

Try like below and confirm.

driver.get("https://soundcloud.com/")

wait = WebDriverWait(driver,30)

wait.until(EC.element_to_be_clickable((By.ID,"onetrust-accept-btn-handler"))).click()

search_field = wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@id='content']//input")))
search_field.send_keys("Sample text")
  • Related