我已经研究过如何在selenium中循环,但是我还没有看到任何对我有用的答案。基本上,这将是我的代码需要遵循的步骤:
这段代码可以工作,但它只是停留在第一行数据上,不会继续到第二行数据,等等。
driver = webdriver.Firefox()
driver.get("https://*****/")
file = open("testfile.csv")
reader = csv.DictReader(file)
data = [row for row in reader]
for row in data:
Name = (row["Name"])
Eadd = (row["Eadd"])
time.sleep(10)
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Name'])[1]/following::input[1]").click()
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Name'])[1]/following::input[1]").send_keys(Name)
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Email'])[1]/following::textarea[1]").click()
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Email'])[1]/following::textarea[1]").clear()
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Email'])[1]/following::textarea[1]").send_keys(Eadd)发布于 2019-06-24 13:20:47
下面是您必须实现的逻辑。
driver = webdriver.Firefox()
driver.get("https://*****/")
file = open("testfile.csv")
data = csv.reader(file) #<== if you have a `,` separated csv then you can use below line rather this.
# data = = csv.reader(csvfile, delimiter=',')
for row in data:
Name = (row["Name"])
Eadd = (row["Eadd"])
# use the below if `,` seperated
#Name = row[0]
#Eadd = row[1]
time.sleep(10)
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Name'])[1]/following::input[1]").click()
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Name'])[1]/following::input[1]").send_keys(Name)
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Email'])[1]/following::textarea[1]").click()
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Email'])[1]/following::textarea[1]").clear()
driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)='Email'])[1]/following::textarea[1]").send_keys(Eadd)https://stackoverflow.com/questions/56737114
复制相似问题