lib/watir/page-container.rb in watir-3.0.0.rc2 vs lib/watir/page-container.rb in watir-3.0.0.rc3

- old
+ new

@@ -31,10 +31,21 @@ document.documentelement end private :page + # Execute the given JavaScript string + def execute_script(source) + document.parentWindow.eval(source.to_s) + rescue WIN32OLERuntimeError, NoMethodError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround + escaped_src = source.to_s.gsub(/[\r\n']/) {|m| "\\#{m}"} + wrapper = "_watir_helper_div_#{::Time.now.to_i + ::Time.now.usec}" + cmd = "var e = document.createElement('DIV'); e.style.display='none'; e.id='#{wrapper}'; e.innerHTML = eval('#{escaped_src}'); document.body.appendChild(e);" + document.parentWindow.execScript(cmd) + document.getElementById(wrapper).innerHTML + end + # The HTML of the current page def html page.outerhtml end @@ -92,6 +103,6 @@ raise ArgumentError, "Argument #{target} should be a string or regexp." end end end # module -end \ No newline at end of file +end