1

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[@class="text6"]').text)
  driver.find_element(By.ID, 'text7').click()

2 Answers 2

2

Try:

for address in addresses:
  # do stuff

You're overwriting addresses with the first element.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.