title: Get all `tr` tags in specific level in web browser c#
body: <p>here is a sample html :   </p>
  
  <pre><code>&lt;form action="/opac-prod/search/briefListSearch.do" method="post" name="search_BrowseSearchHitsForm"&gt;
  &lt;table id="printTable" width="100%" align="center" dir="ltr"&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style="font-family:tahoma;font-size:11px"&gt;
                  &lt;table border="0" align="right" cellspacing="0"&gt;
                      &lt;tbody&gt;
                          -- I want to get just this level tr tags , not in their children
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                          &lt;tr&gt;&lt;/tr&gt;
                      &lt;/tbody&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p></p>
  
  <p>I want to get all html elements which are tagged in <code>tr</code> but Not In All Levels. I mean that If I use a foreach loop to perform this, I can't actually do this. because I want to get All <code>tr</code> tags in <strong>just</strong> the last <code>tbody</code> tag (they have same code inside), not in their children too.
  How can I perform this ?</p>
  
  <p>I try this foreach loop but it goes on each <code>tr</code> tag that is there after <code>LoopElement</code> :  </p>
  
  <pre><code>var htmlElement = wb.Document.GetElementsByTagName("body")[0].GetElementsByTagName("form")[0].GetElementsByTagName("table")["printTable"];
              if (htmlElement != null)
              {
                  var elements = htmlElement.GetElementsByTagName("tbody")[0].GetElementsByTagName("tr")[0].GetElementsByTagName("td")[0].GetElementsByTagName("table")[0].GetElementsByTagName("tbody")[0];
                  foreach (HtmlElement element in elements.GetElementsByTagName("tr"))
                  {
                      if (element.GetElementsByTagName("td")[0].GetElementsByTagName("table") != null)
                      {
                          try
                          {
                              var LoopElement =
                                  element.GetElementsByTagName("td")[0].GetElementsByTagName("table")[0].GetElementsByTagName("tbody")[0].GetElementsByTagName("tr");
                              foreach (HtmlElement element1 in LoopElement)
                              {
                                   // This Loop 
                              }
                          }
                          catch
                          {
                              continue;
                          }
                      }
                  }
  </code></pre>