diff --git a/lib/capybara/webkit/node.rb b/lib/capybara/webkit/node.rb index 57dab42..0bf37a8 100644 --- a/lib/capybara/webkit/node.rb +++ b/lib/capybara/webkit/node.rb @@ -1,10 +1,12 @@ module Capybara::Webkit class Node < Capybara::Driver::Node - NBSP = "\xC2\xA0" - NBSP.force_encoding("UTF-8") if NBSP.respond_to?(:force_encoding) + def visible_text + Capybara::Helpers.normalize_whitespace(invoke("text")) + end + alias_method :text, :visible_text - def text - invoke("text").gsub(NBSP, ' ').gsub(/\s+/u, ' ').strip + def all_text + Capybara::Helpers.normalize_whitespace(invoke("allText")) end def [](name) diff --git a/spec/driver_spec.rb b/spec/driver_spec.rb index 43f6f7b..a8a62cc 100644 --- a/spec/driver_spec.rb +++ b/spec/driver_spec.rb @@ -107,7 +107,7 @@ describe Capybara::Webkit::Driver do it "returns a node's text" do driver.within_frame("f") do - driver.find("//p").first.text.should == "goodbye" + driver.find("//p").first.visible_text.should == "goodbye" end end @@ -216,7 +216,7 @@ describe Capybara::Webkit::Driver do it "should redirect without content type" do visit("/form") driver.find("//input").first.click - driver.find("//p").first.text.should == "" + driver.find("//p").first.visible_text.should == "" end it "returns the current URL when changed by pushState after a redirect" do @@ -312,6 +312,9 @@ describe Capybara::Webkit::Driver do
Can't see me too
+
+ Some of this text is hidden! +