Skip to content

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 thoughtbot#437.
  • Loading branch information
betelgeuse committed Jan 21, 2013
1 parent a4a0034 commit a01bea5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/driver_spec.rb
Original file line number Diff line number Diff line change
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
5 changes: 4 additions & 1 deletion src/capybara.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ Capybara = {
text: function (index) {
var node = this.nodes[index];
var type = (node.type || node.tagName).toLowerCase();
if (type == "textarea") {
// SVG elements do not have the non standardized innerText attribute
if (node.namespaceURI == 'http://www.w3.org/2000/svg') {

This comment has been minimized.

Copy link
@mhoran

mhoran Jan 21, 2013

What about if (type == "svg")?

This comment has been minimized.

Copy link
@betelgeuse

betelgeuse Jan 21, 2013

Author Owner

type == "text" for for example the element in the spec

return node.textContent;
} else if (type == "textarea") {
return node.innerHTML;
} else {
return node.innerText;
Expand Down

0 comments on commit a01bea5

Please sign in to comment.