title: XPath Query to check if td has certain children (C# + Selenium)
body: <p>I hope someone can help me out, I am stuck with an XPath expression. I have the following HTML extracted from a a tennismatch with C# and Selenium:</p>
  
  <pre><code>&lt;tbody&gt;
    &lt;tr id="g_2_CvUnLIxC" class="tr-first stage-live" style="cursor: pointer;" title=""&gt;
      &lt;td rowspan="2" class="cell_ib icons left"&gt;&lt;span class="icons left"&gt;&lt;span class="tomyg icon0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td rowspan="2" class="cell_ad time  time-playing" title="Click for match detail!"&gt;21:00&lt;/td&gt;
      &lt;td rowspan="2" class="cell_aa timer  playing" title="Click for match detail!"&gt;&lt;span&gt;Set 3&lt;/span&gt;&lt;/td&gt;
      &lt;td class="cell_xh serve-home" title=""&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td class="cell_ab team-home" title="Click for match detail!"&gt;&lt;span class="padl"&gt;Barrientos N. (Col)&lt;/span&gt;&lt;/td&gt;
      &lt;td class="cell_sc score-home  bold playing"&gt;1&lt;/td&gt;
      &lt;td class="cell_sd part-bottom" title="Click for match detail!"&gt;7&lt;/td&gt;
      &lt;td class="cell_se part-bottom" title="Click for match detail!"&gt;2&lt;/td&gt;
      &lt;td class="cell_sf part-bottom"&gt;4&lt;/td&gt;
      &lt;td class="cell_sg part-bottom"&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td class="cell_sh part-bottom"&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td class="cell_sp part-bottom highlight-highlighted"&gt;15&lt;/td&gt;
      &lt;td rowspan="2" class="cell_ia icons"&gt;&lt;span class="icons"&gt;&lt;span class="tv icon1"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td rowspan="2" class="cell_oq comparison"&gt;&lt;span class="icons"&gt;&lt;span class="clive icon0"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr id="x_2_CvUnLIxC" class="tr-first stage-live" style="cursor: pointer;" title=""&gt;
      &lt;td class="cell_xa serve-away" title=""&gt;&lt;span class="icons" title=""&gt;&lt;span class="tennis-serve" title="Serving player"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
      &lt;td class="cell_ac team-away" title="Click for match detail!"&gt;&lt;span class="padl"&gt;Lapentti G. (Ecu)&lt;/span&gt;&lt;/td&gt;
      &lt;td class="cell_ta score-away  bold playing" title="Click for match detail!"&gt;1&lt;/td&gt;
      &lt;td class="cell_tb part-top"&gt;5&lt;/td&gt;
      &lt;td class="cell_tc part-top"&gt;6&lt;/td&gt;
      &lt;td class="cell_td part-top"&gt;5&lt;/td&gt;
      &lt;td class="cell_te part-top"&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td class="cell_tf part-top"&gt;&amp;nbsp;&lt;/td&gt;
      &lt;td class="cell_to part-top highlight-highlighted" title="Click for match detail!"&gt;30&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
  </code></pre>
  
  <p>Out of this I want to extract which player is currently serving, which is displayed by a ball symbol that is shown with the following span-tag inside a td-tag:</p>
  
  <pre><code>&lt;span class="icons" title=""&gt;&lt;span class="tennis-serve" title="Serving player"&gt;&lt;/span&gt;&lt;/span&gt; 
  </code></pre>
  
  <p>This is either set in serve-home or in serve-away:</p>
  
  <pre><code>&lt;td class="cell_xh serve-home" title=""&gt;&amp;nbsp;&lt;/td&gt;
  &lt;td class="cell_xa serve-away" title=""&gt;&lt;span class="icons" title=""&gt;&lt;span class="tennis-serve" title="Serving player"&gt;&lt;/span&gt;&lt;/span&gt;&lt;/td&gt;
  </code></pre>
  
  <p>What I want is something like the following pseudo code resembles:</p>
  
  <pre><code>IWebElement id = driver.FindElement(union ((By.Id(id1),By.Id(id2)); 
  IWebElement serve = id.FindElement(By.XPath("td that contains &lt;span class="icons" title=""&gt;&lt;span class="tennis-serve" title="Serving player"&gt;&lt;/span&gt;&lt;/span&gt; 
  
  String serv
  
  er = serve.getAttribut("class"); //contains then serve-home or serve-away
  
  Find attached an example of what the website looks like, I want to find out if the ball is displayed at player 1 or 2:
  [link](http://i44.tinypic.com/2e157v6.png)
  
  Thank you in advance!
  </code></pre>
  
  <p>UPDATE1:</p>
  
  <pre><code>                IWebElement id1 = driver.FindElement(By.Id(txt_ID1.Text));
                  IWebElement id2 = driver.FindElement(By.Id(txt_ID2.Text));
  
                  ReadOnlyCollection&lt;OpenQA.Selenium.IWebElement&gt; elements = id1.FindElements(By.XPath("td[contains(@class,'serve')]"));
                  ReadOnlyCollection&lt;OpenQA.Selenium.IWebElement&gt; elements2 = id2.FindElements(By.XPath("td[contains(@class,'serve')]"));
  
                  foreach (IWebElement i in elements)
                  {
                      if (i.GetAttribute("innerHTML").Contains("span"))
                          Console.WriteLine(i.GetAttribute("class"));
                  }
  
                  foreach (IWebElement i in elements2)
                  {
                      if (i.GetAttribute("innerHTML").Contains("span"))
                          Console.WriteLine(i.GetAttribute("class"));
                  }
  </code></pre>
  
  <p>}</p>