diff --git a/lib/webrat/core/locators/link_locator.rb b/lib/webrat/core/locators/link_locator.rb
index <HASH>..<HASH> 100644
--- a/lib/webrat/core/locators/link_locator.rb
+++ b/lib/webrat/core/locators/link_locator.rb
@@ -45,10 +45,14 @@ module Webrat
       end
 
       def replace_nbsp(str)
-        if str.respond_to?(:force_encoding)
-          str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
+        if str.respond_to?(:valid_encoding?)
+          if str.valid_encoding?
+            str.gsub(/\xc2\xa0/u, ' ')
+          else
+            str.force_encoding('UTF-8').gsub(/\xc2\xa0/u, ' ')
+          end
         else
-          str.gsub("\xc2\xa0", ' ')
+          str.gsub(/\xc2\xa0/u, ' ')
         end
       end
Fix replacing of &nbsp;, aka &#<I>; so it works on <I>