lib/watir/ie-class.rb in watir-2.0.1 vs lib/watir/ie-class.rb in watir-2.0.2.rc1

- old
+ new

@@ -366,10 +366,17 @@ # Return the title of the document def title @ie.document.title end + # The document standards mode used by IE + # can be overridden in the html with: <meta http-equiv="x-ua-compatible" content="IE=8"> + def document_mode + @ie.document.documentMode.to_i + end + + # Return the status of the window, typically from the status bar at the bottom. def status return @ie.statusText end @@ -411,11 +418,19 @@ end # Execute the given JavaScript string def execute_script(source) document.parentWindow.eval(source.to_s) - rescue WIN32OLERuntimeError - document.parentWindow.execScript(source.to_s) + rescue WIN32OLERuntimeError #if eval fails we need to use execScript(source.to_s) which does not return a value, hence the workaround + wrapper = "_watir_helper_div_#{rand(100000)}" + escaped_src = source.to_s + escaped_src = escaped_src.gsub("'", "\\\\'") + cmd = "var e= document.createElement('DIV'); e.id='#{wrapper}'; e.innerHTML= eval('#{escaped_src}');document.body.appendChild(e);" + document.parentWindow.execScript(cmd) + wrapper_obj = document.getElementById(wrapper) + result_value = wrapper_obj.innerHTML + wrapper_obj.style.display = 'none' + result_value end # clear the list of urls that we have visited def clear_url_list @url_list.clear