Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

Commit

Permalink
Make Node#text work for svg elements
Browse files Browse the repository at this point in the history
svg elements don't return to the non standard innerText attribute so
fall back on the standard textContent when innerText is null.

Fixes #437.
  • Loading branch information
betelgeuse authored and mhoran committed Feb 7, 2013
1 parent a70b7c4 commit 2f3832f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/driver_spec.rb
Expand Up @@ -472,6 +472,26 @@ def visit(url, driver=driver)
end
end

context "svg app" do
let(:driver) do
driver_for_html(<<-HTML)
<html>
<body>
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" height="100">
<text x="10" y="25" fill="navy" font-size="15" id="navy_text">In the navy!</text>
</svg>
</body>
</html>
HTML
end

before { visit("/") }

it "should handle text for svg elements" do
driver.find("//*[@id='navy_text']").first.text.should == "In the navy!"
end
end

context "console messages app" do
let(:driver) do
driver_for_html(<<-HTML)
Expand Down
2 changes: 1 addition & 1 deletion src/capybara.js
Expand Up @@ -41,7 +41,7 @@ Capybara = {
if (type == "textarea") {
return node.innerHTML;
} else {
return node.innerText;
return node.innerText || node.textContent;
}
},

Expand Down

0 comments on commit 2f3832f

Please sign in to comment.