I have created an autofill with python selenium and I have a small problem with it, the autofill stops by itself after it has reached the autofill ROW 15 or 18 or 20 and when I restart the autofill it starts from the beginning then I have the problem that I have the web form 2x-3x with the same data.
Do you perhaps have a solution so that my autofill, for example, the autofill stops at ROW 15 and I restart it, it starts again from ROW 15 so that I do not have the same data several times
enter image description here
#-------------------------------------------------------------------------------
# Imports
import csv
from selenium import webdriver
from selenium.webdriver.common.by import By
import time
#-------------------------------------------------------------------------------
# Setup
name = 0
age = 1
score = 2
with open('data.csv', 'r', encoding='utf8', errors='ignore') as csv_file:
csv_reader = csv.reader(csv_file)
#-------------------------------------------------------------------------------
# Web Automation
for line in csv_reader:
driver = webdriver.Chrome()
driver.get('https://mysite.domain/?page_id=311')
Add_to = driver.find_element(By.XPATH, "//*[@id='site-content']")
Add_to.click()
time.sleep(3)
driver.get('https://mysite.domain/?page_id=385')
name_field = driver.find_element(By.XPATH, "//*[@id='first_name']")
name_field.send_keys(line[0])
age_field = driver.find_element(By.XPATH, "//*[@id='last_name']")
age_field.send_keys(line[1])
Adress = driver.find_element(By.XPATH, "//*[@id='address_1']")
Adress.send_keys(line[2])
Zip = driver.find_element(By.XPATH, "//*[@id='postcode']")
Zip.send_keys(line[3])
City = driver.find_element(By.XPATH, "//*[@id='city']")
City.send_keys(line[4])
Phone = driver.find_element(By.XPATH, "//*[@id='phone']")
Phone.send_keys(line[5])
Email = driver.find_element(By.XPATH, "//*[@id='email']")
Email.send_keys(line[6])
Submit = driver.find_element(By.XPATH, "//*[@id='Submit']")
Submit.click()
time.sleep(3)
#-------------------------------------------------------------------------------
easy992 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.