How to Iterate through a list in Google's search bar

Question:

I am trying to search items in google’s search bar where the items come from an excel spreadsheet. I have no issue importing the items from excel to python but my script never actually enters any of the items into Google’s search bar. What is wrong with my loop? I want it to search every item in excel. Thanks.

from ast import Return
from operator import index
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import pandas as pd
import time

df = pd.read_csv("C:\Users\Carson\properties1.csv")
indexx = [df]

driver = webdriver.Chrome("C:/Users/Carson/Desktop/chromedriver.exe")
driver.get("https://www.google.com")

try:
    for element in indexx:
       search =  WebDriverWait(driver, 7).until(EC.presence_of_element_located((By.NAME,'q')))
       search.click()
       search.send_keys(element)
       search.send_keys(Keys.RETURN)
       driver.back()
       
except:
    print("Loop Failed")
    driver.quit()
 
Asked By: Carson Cramer

||

Answers:

The problem seems to be importing from Excel, because your code worked for me when I run the loop over a list of strings.

Check what comes out of Excel (print the indexx list).

Hope I helped,

Jonathan

Answered By: ylj

I solved my issue by using the line of code:

for i, row in df.iterrows():
Answered By: Carson Cramer