Permalink
Browse files

backport execute_script from Watir 3.0.0.rc2

  • Loading branch information...
1 parent ba67405 commit 6af560c87b51e9bfb5e35cbf0b480d8e40638175 @abaird abaird committed Feb 18, 2012
Showing with 7 additions and 3 deletions.
  1. +1 −1 VERSION
  2. +6 −2 watir/lib/watir/ie-class.rb
View
@@ -1 +1 @@
-1.9.9
+1.9.10
@@ -417,8 +417,12 @@ def inspect
# 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, 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_#{rand(100000)}"
+ 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
# clear the list of urls that we have visited

0 comments on commit 6af560c

Please sign in to comment.