rspec-html

0.3.5
Light Mode Dark Mode

XPath

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.

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).to eql '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>
My content

Documentation generated by rspec-documentation