title: How to locate the grandparent of elements using Selenium (Python) in a loop
body: <p>I am trying to append the name of a value which it's child element is less then 120.</p>
  <p>My code is</p>
  <pre><code>list = []
  rate = driver.find_elements(By.XPATH, '//span[@class=&quot;sFive&quot;]')
  for e in rate:
      if int(e.text) &lt; 120:
          title=e.find_element(By.XPATH, x).text #find ancestor element
          list.append(title)
  
  print(list)
  </code></pre>
  <p>The x is where I need to find the grandparent which is the 21st span element up that branch.</p>
  <p>The span element is</p>
  <pre><code>&lt;span data-slnm=&quot;Brand&quot; class=&quot;ng-star-inserted&quot;&gt;Inter&lt;/span&gt;
  </code></pre>