{"id":8043,"date":"2015-11-22T02:59:58","date_gmt":"2015-11-22T02:59:58","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2015\/11\/22\/how-do-i-get-the-html-in-an-element-using-capybara-open-source-projects-jnicklas-capybara\/"},"modified":"2022-08-30T15:39:09","modified_gmt":"2022-08-30T15:39:09","slug":"how-do-i-get-the-html-in-an-element-using-capybara-open-source-projects-jnicklas-capybara","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2015\/11\/22\/how-do-i-get-the-html-in-an-element-using-capybara-open-source-projects-jnicklas-capybara\/","title":{"rendered":"How do I get the HTML in an element using Capybara?-open source projects jnicklas\/capybara"},"content":{"rendered":"<p><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/cfa71089e69037dd7e7eab858e7c4f69?s=128&amp;d=identicon&amp;r=PG\" \/> <strong>Steve<\/strong><\/p>\n<p>In my environment, find returns a Capybara::Element &#8211; that responds to the :native method as Eric Hu mentioned above, which returns a Selenium::WebDriver::Element (for me). Then :text gets the contents, so it could be as simple as:<\/p>\n<pre><code>results = find(:xpath, \"\/\/td[@id='#{cell_id}']\")\ncontents = results.native.text\n<\/code><\/pre>\n<p>if you&#8217;re looking for the contents of a table cell. There&#8217;s no content, inner_html, inner_text, or node methods on a Capybara::Element. Assuming people aren&#8217;t just making things up, perhaps you get something different back from find depending on what else you have loaded with Capybara.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Steve In my environment, find returns a Capybara::Element &#8211; that responds to the :native method as Eric Hu mentioned above, which returns a Selenium::WebDriver::Element (for me). Then :text gets the contents, so it could be as simple as: results = find(:xpath, &#8220;\/\/td[@id=&#8217;#{cell_id}&#8217;]&#8221;) contents = results.native.text if you&#8217;re looking for the contents of a table cell. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"class_list":["post-8043","post","type-post","status-publish","format-standard","hentry","category-capybara","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8043","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=8043"}],"version-history":[{"count":1,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8043\/revisions"}],"predecessor-version":[{"id":8668,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/8043\/revisions\/8668"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=8043"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=8043"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=8043"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}