Web Search Automation with Python/Selenium

Question:

enter image description hereI’m trying to access a search box on a website and I keep getting a ‘not JSON serializable’ error.

Not quite sure what I am doing wrong should be pretty simple, can anyone spot the issue, is it because I haven’t set a specific file path for ‘webdriver.Chrome()’ or is it because the website has a cookie pop-up that I need to act before the search box will be accessible?

# Import necessary libraries
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import time

# Set up the webdriver
driver = webdriver.Chrome()

# Navigate to the website and search for the product
driver.get("https://www.example")
search_bar = driver.find_element(id, "search-term")
search_bar.send_keys("test")
search_bar.send_keys(Keys.RETURN)
Asked By: T1m_McG

||

Answers:

search_bar = driver.find_element(id, "search-term")

You are passing the builtin function id to the .find_element method, but that’s not a valid argument for the first parameter of .find_element.

What you probably want is:

from selenium.webdriver.common.by import By
# ...
search_bar = driver.find_element(By.ID, "search-term")
Answered By: sytech