title: How to use Python variable in an XPath expression?
body: <p>I am trying to get all the <code>followers name</code> from this website <a href="https://www.quora.com/profile/Karan-Bansal-3/followers" rel="nofollow">https://www.quora.com/profile/Karan-Bansal-3/followers</a></p>
  
  <p>Since the whole page is not loaded at once, I am using this everytime in a loop : </p>
  
  <pre><code>driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  </code></pre>
  
  <p>Now since I can't select all the element at once, I am trying to use indexing to find the element in the loop.</p>
  
  <pre><code>people = driver.find_element_by_xpath("//div[@class='pagedlist_item'][i]/*/div[@class='ObjectCard-header']/a[@class='user']")
  </code></pre>
  
  <p>Here as you can see, I am trying to give the indexing using <code>[i]</code> which clearly doesn't work and in place of it, if I give [1] or any number it works well. So how can I select the element one by one.</p>
  
  <p>Code snippet : </p>
  
  <pre><code>i=1
  target = open(filename,'w')
  driver.get('https://www.quora.com/profile/Karan-Bansal-3/followers')
  while True:
  driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  people = driver.find_element_by_xpath("//div[@class='pagedlist_item'][i]/*/div[@class='ObjectCard-header']/a[@class='user']")
  target.write(people.text)
  target.write("\n")
  i = i+1
  </code></pre>