title: XPath find parent of a child element
body: <p>I have a structure such as this:</p>
  
  <pre><code>&lt;div class="Container"&gt;
    &lt;div class="HighlightContainer"&gt;
      &lt;div class="NodeTextHighlightContainer"&gt;
        &lt;span class="TreeItemSelected"&gt;Products&lt;/span&gt;
      &lt;/div&gt;
      &lt;button class="ContainerSelectedMenu" type="button"&gt;&lt;/button&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>Because of how the DOM behaves and trying to stay dynamic, I can only target the span that contains text Products. using something like:</p>
  
  <pre><code>Driver.FindElement(By.XPath("//div[contains(@class, 'Container')]/descendant::span[text() = 'Products']"));
  </code></pre>
  
  <p>However, I need to target the button where <code>class="ContainerSelectedMenu"</code> based of that span element, what is the best approach? Something like getting the parent div of the child of Container then finding the button element.</p>