I prefer to minimize the usage of XPath in webdriver when locating elements, but still want the ability to access child elements from previously identified ones. For example:
Consider the following HTML structure:
<div id="myelement">
<table class="myclass">
<tbody>
<tr>
<td>something</td>
<td>
<table>
<tbody>
...
</tbody>
</table>
</td>
</tr>
<tr>
...
</tr>
</tbody>
</table>
</div>
If I have a CSS selector like this:
driver.find_elements('div#myelement table.myclass > tbody > tr')
I want to separate this into finding the table element and the rows without having to refer back to the entire table expression. This is achievable with XPath like so:
table = driver.find_element(:xpath, "//div[@id='myelement']//table[@classname='myclass']")
rows = table.find_elements(:xpath, 'tbody/tr')
Attempting to do the same with CSS like using JQuery $('div#myelement table.myclass').find('> tbody > tr') led to an error: `assert_ok': An invalid or illegal string was specified (Selenium::WebDriver::Error::UnknownError)
Although removing the first '>' would work, it does not limit the selection to immediate children. So, how can I achieve this correctly using only CSS?