Why am I not able to cycle through the rows in my csv file with my selenium code?

Viewed 18

I have a csv file, names.csv, that has a list of names. I would like to use this file in my python code that is using selenium to type these names in a search bar and copy the output to a new list, and then append that list to another csv file. As of right now, the code works, but just for the first item in names.csv and then stops. I've tried using continue, next, etc. and tried just having a local list in that file that is then cycled through with no luck.

names.csv:

Daffy Duck
Mickey Mouse
Minnie Mouse
Tom Brady
Peyton Manning
Lebron James

findEmail.py

contacts = []
pattern = re.compile(r"[\w\.]+@[\w\.]+")


with open('names.csv', 'r') as csv_file:
        csv_reader = csv.reader(csv_file)

        for rows in csv_reader:
            m.send_keys(rows + " Counseling")
            #this following code finds the emails i'm looking for, no problems with it
            element = driver.find_element(By.XPATH, '/html/body/div[3]/div/div[2]/div/a/div[1]/p/strong/a')
            match = pattern.match(element.text)
            if match:
                contacts.append(element.text)

print(contacts)

0 Answers
Related