title: Selenium + Python: finding elements by xpath with a loop
body: <p>I'm writing a testcase about moving markers on multiple sliders. I've done it with behave, but I call every slider and every marker on it without using a loop, like this one: <a href="https://github.com/Ketochka/Selenium_Behave_tests/blob/master/steps/Selenium_slider_dance.py" rel="nofollow">https://github.com/Ketochka/Selenium_Behave_tests/blob/master/steps/Selenium_slider_dance.py</a>
  It works, but I want code to be shorter.</p>
  
  <p>I try to use it this way(below), but it doesn't work.
  Can anyone please help with how to find array of elements with a loop?</p>
  
  <pre><code>import unittest
  import time
  from selenium import webdriver
  from selenium.webdriver.support.ui import WebDriverWait
  
  class Slider_Test(unittest.TestCase):
  
      def setUp(self):
          self.driver = webdriver.Firefox()
  
      def test_sortable_elements(self):
          driver = self.driver
          driver.get("http://jqueryui.com/slider/#multiple-vertical")
          frame_ = driver.find_element_by_tag_name("iframe")
          driver.switch_to_frame(frame_)
          driver.implicitly_wait(5)
          eq_current = []
          eq_marker = []
          for i in range(1,8):
              eq_current[i] = driver.find_element_by_xpath("//body/div[@id='eq']/span["+str(i)+"]/div")
              eq_marker[i] = driver.find_element_by_xpath("//body/div[@id='eq']/span["+str(i)+"]/span")
              time.sleep(.1)
              print(eq_current[i].size['height'])
  
          def tearDown(self):
              self.driver.close()
              self.driver.quit()
  
  if __name__ == '__main__':
      suite = unittest.TestLoader().loadTestsFromTestCase(Slider_Test)
      unittest.TextTestRunner().run(suite)
  </code></pre>
  
  <p><a href="https://drive.google.com/open?id=0BxKq4HdrUqSkOEtxRzJXTkNiQzQ" rel="nofollow">https://drive.google.com/open?id=0BxKq4HdrUqSkOEtxRzJXTkNiQzQ</a></p>