Does anyone know why when using Selenium - This for loop would iterate over my list and that at some point it just replaces all list elements with a single list element as some point. I'm not sure which index it decides to do it from addresses
but at some point in the loop it will just replaced the addresses
list items with just a single item and then it kills the loop. I have to recreate the list from the addresses
list element # it stopped on. What could be happening? Thank you
addresses = ['address','address','address']
for addresses in addresses:
element = wait.until(EC.visibility_of_element_located((By.LINK_TEXT, 'text1')))
driver.find_element(By.LINK_TEXT, 'text2').click()
element = wait.until(EC.visibility_of_element_located((By.ID, 'text3')))
driver.find_element(By.ID,'idcustomername').send_keys(addresses[0])
driver.find_element(By.ID,'address').send_keys(addresses[1])
driver.find_element(By.ID, 'text4').click()
element = wait.until(EC.visibility_of_element_located((By.ID, 'text5')))
leads.append(driver.find_element(By.XPATH, '//div[@]').text)
driver.find_element(By.ID, 'text7').click()
CodePudding user response:
Try:
for address in addresses:
# do stuff
You're overwriting addresses with the first element.
CodePudding user response:
Dave Cook beat me to it but here's an explanation: The name for your iterator variable and the list you are iterating through is the same, they have to be different otherwise you are overwriting the addresses with the first element in your list.