title: Using css child selector in ruby selenium-webdriver element find_elements
body: <p>I want to avoid using XPath where possible when finding elements in webdriver, but be able to reference child elements from already found elements e.g.</p>
  
  <p>For the following html:</p>
  
  <pre><code>&lt;div id="myelement"&gt;
      &lt;table class="myclass"&gt;
         &lt;tbody&gt;
             &lt;tr&gt;
                 &lt;td&gt;something&lt;/td&gt;
                 &lt;td&gt;
                     &lt;table&gt;
                         &lt;tbody&gt;
                             ...
                         &lt;/tbody&gt;
                     &lt;/table&gt;
                 &lt;/td&gt;
             &lt;/tr&gt;
             &lt;tr&gt;
                 ...
             &lt;/tr&gt;
         &lt;/tbody&gt;
      &lt;/table&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have a css expression:</p>
  
  <p>driver.find_elements('div#myelement table.myclass > tbody > tr')</p>
  
  <p>I want to break this up into the table element and the rows, without having to refer back to the table expression. e.g. for XPath:</p>
  
  <pre><code>table = driver.find_element(:xpath, "//div[@id='myelement']//table[@classname='myclass']")
  
  rows = table.find_elements(:xpath, 'tbody/tr')
  </code></pre>
  
  <p>I've tried the following, which works using JQuery $('div#myelement table.myclass').find('> tbody > tr')</p>
  
  <pre><code>table = driver.find_element(:css, 'div#myelement table.myclass')
  
  rows = table.find_elements(:css, '&gt; tbody &gt; tr')
  </code></pre>
  
  <p>This causes an error `assert_ok': An invalid or illegal string was specified (Selenium::WebDriver::Error::UnknownError)</p>
  
  <p>Removing the first '>' of course works, however means decendant tbody's are selected and not just immediate children.</p>
  
  <p>How can I do this correctly using just css?</p>