If the provided DOM navigation syntax does not provide a way for you to definitively select the required element, XPath is available via the #xpath method which delegates directly to the underlying Nokogiri::HTML::Document object.
Side-by-side view
Spec
subject(:document)do parse_html('<table><tr><td>My content</td></table>') end
it'matches using xpath'do expect(document.xpath('//table/tr/td').text).toeql'My content' end
Output
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <table> <tr> <td>My content</td> </tr> </table> </body></html>
Rendered Output
My content
subject(:document)do parse_html('<table><tr><td>My content</td></table>') end
it'matches using xpath'do expect(document.xpath('//table/tr/td').text).toeql'My content' end
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><body> <table> <tr> <td>My content</td> </tr> </table> </body></html>