title: Iterating through multiple elements in one for loop using selenium
body: <p>I'm trying to scrape through multiple containers on a website to see if a certain item exists. I want to compare a specific value and if an item is found with that value it will write the price for that item and a link to where to buy it in a csv file. </p>
  
  <p>I have managed to make a for loop that cycles through the value I am trying to match, however I cannot figure out how to pull the other elements I need with it. It ends up returning the values for the first container on the page and not the one that matched. </p>
  
  <p>I have tried putting them inside the for loop as well as outside. I realize it isn't working because they are only finding a single element and it's not being told which container to pull it from, but I did something similar in my other script and it worked perfectly. </p>
  
  <p>I also tried nesting for loops inside each other but for obvious reasons that didn't work out either. What would be the best way to handle such a situation?</p>
  
  <pre><code>values = WebDriverWait(driver, 2).until(EC.presence_of_all_elements_located((By.XPATH, "//*[contains(@class,'text-center') and contains(text(),'Wear:')]")))
  price = driver.find_element_by_class_name("item-price-display").text
  buy_link = driver.find_element_by_css_selector("a.btn-xs").get_attribute('href')
  print(len(values))
  for value in values:
      wear = value.text.replace("Wear: ", "")
      print(wear)
      if wear == condition:    
          print(buy_link,price)
          f.write(buy_link + "," + price)
          break
  </code></pre>
  
  <p>Full Code:</p>
  
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.by import By
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.support.ui import WebDriverWait
  from selenium.webdriver.support import expected_conditions as EC
  profile = webdriver.FirefoxProfile()
  profile.set_preference("permissions.default.image", 2) # Block all images to load websites faster.
  driver = webdriver.Firefox(firefox_profile=profile)
  f =  open("file.csv",'r+')
  url = "http://bitskins.com"
  driver.get(url)
  elem = driver.find_element_by_name("market_hash_name")
  key = "Dragon Lore"
  condition = "0.11940288"
  elem.send_keys(key,Keys.RETURN)
  import time
  time.sleep(3)
  values = WebDriverWait(driver, 2).until(EC.presence_of_all_elements_located((By.XPATH, "//*[contains(@class,'text-center') and contains(text(),'Wear:')]")))
  print(len(values))
  for value in values:
      price = driver.find_element_by_class_name("item-price-display").text 
      buy_link = driver.find_element_by_css_selector("a.btn-xs").get_attribute('href')
      wear = value.text.replace("Wear: ", "")
      print(wear)
      if wear == condition:
  
          print(buy_link,price)
          f.write(buy_link + "," + price)
          break
  
  </code></pre>
  
  <p>Expected Results: (Also I'm trying to figure out how to select the 4th button and not the first button next to the add to cart.)</p>
  
  <p><a href="https://bitskins.com/view_item?app_id=730&amp;item_id=14983017710" rel="nofollow noreferrer">https://bitskins.com/view_item?app_id=730&amp;item_id=14983017710</a>
  $1,355.23</p>
  
  <p>Results I'm Getting:</p>
  
  <p><a href="https://steamcommunity.com/profiles/76561198380422063/inventory/#730_2_15685089707" rel="nofollow noreferrer">https://steamcommunity.com/profiles/76561198380422063/inventory/#730_2_15685089707</a> $1,350.00</p>