title: Python selenium to extract elements with xpath and for loop
body: <p>I am using Python/Selenium to extract some text from a website to further sort it in Google Sheets.</p>
  <p>There are 15 headers for which I need to extract text. The text is found under each header in tag h5.</p>
  <p>Here's one extract of a header:</p>
  <pre><code>&lt;tr class=&quot;dayHeader&quot;&gt;
   &lt;td colspan=&quot;7&quot; style=&quot;padding:10px 0;&quot;&gt;
    &lt;hr&gt;
    &lt;h5&gt;&amp;nbsp;&amp;nbsp;Tuesday - 02 February 2021&lt;/h5&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
  </code></pre>
  <p>What I have done is the following:</p>
  <pre><code>headers = driver.find_elements_by_tag_name('h5')
  results = []
  
  for header in headers:
      result = header.text
      results.append(result)
  </code></pre>
  <p>I'd prefer fetching the text from h5 going by the class above this tag, like so:</p>
  <pre><code>headers = driver.find_element(By.XPATH,&quot;//tr[@class='dayHeader']/h5&quot;)
  </code></pre>
  <p>and add it to the mentioned for loop, but I can't seem to get this line to work. How can I do this?</p>