0
Path = r"C:\WebDriverEdge\chromedriver.exe"
service = Service(Path)
options = Options()
options.add_argument('--user-data-dir=C:\\Users\\Admin\\AppData\\Local\\Google\\Chrome\\User Data\\')
options.add_argument("--profile-directory=Profile 1")

#connect to driver
driver = webdriver.Chrome(service = service, options = options)
driver.get("https://open.spotify.com/search")
x_path = '//*[@id="main"]/div/div[2]/div[1]/header/div[3]/div/div/form/input'

search = driver.find_element(By.XPATH, x_path)

action = webdriver.ActionChains(driver)
action.move_to_element(search).send_keys("Let me").perform()

I try to click on search bar at Spotify and use it to search. My problem is when I already login my code get error "unable to find element" but without sign in I can fill the search bar easily. I don't know why. Is any one run into this before? Thanks in advance

p/s: XPath still the same

huy luong
  • 9
  • 1

1 Answers1

0

I'd rather use this form[role='search'] input css with explicit wait like below:

driver.get("https://open.spotify.com/search")
driver.maximize_window()
wait = WebDriverWait(driver, 20)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "form[role='search']"))).send_keys('Let me')

Imports:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
cruisepandey
  • 28,520
  • 6
  • 20
  • 38