How I can check html content on the page with capybara?
page.should have_text('this is <b>bold</b> "text"')
output:
Failure/Error: page.should have_text('this is <b>bold</b> "text"') expected there to be this is <b>bold</b> \"text\" in "....this is bold \"text\"....."
Your code doesn't work as Capybara's has_text?
(and thus have_text
) method checks text, not html source of the element it is invoked on.
If you use driver that supports Javascript evaluation (e.g. Selenium, Poltergeist or Capybara-Webkit) you can get inner HTML of the element using Javascript:
html = page.evaluate_script("document.getElementById('answer-15988092').innerHTML")
html.should include('this is <b>bold</b> "text"')
If you want to assert that the entire HTML of the page contains an element you can use html
method that returns page source:
page.html.should include('this is <b>bold</b> "text"')
Usually I prefer javascript evaluation as it's more restrictive.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With