lib/watir/ie-class.rb in watir-2.0.3 vs lib/watir/ie-class.rb in watir-2.0.4
- old
+ new
@@ -14,42 +14,42 @@
@@attach_timeout = timeout
end
# Return the options used when creating new instances of IE.
# BUG: this interface invites misunderstanding/misuse such as IE.options[:speed] = :zippy]
- def self.options
- {:speed => self.speed, :visible => self.visible, :attach_timeout => self.attach_timeout, :zero_based_indexing => self.zero_based_indexing}
- end
+ def self.options
+ {:speed => self.speed, :visible => self.visible, :attach_timeout => self.attach_timeout, :zero_based_indexing => self.zero_based_indexing}
+ end
# set values for options used when creating new instances of IE.
- def self.set_options options
- options.each do |name, value|
- send "#{name}=", value
- end
- end
- # The globals $FAST_SPEED and $HIDE_IE are checked both at initialization
- # and later, because they
- # might be set after initialization. Setting them beforehand (e.g. from
- # the command line) will affect the class, otherwise it is only a temporary
- # effect
- @@speed = $FAST_SPEED ? :fast : :slow
- def self.speed
- return :fast if $FAST_SPEED
- @@speed
- end
- def self.speed= x
- $FAST_SPEED = nil
- @@speed = x
- end
- @@visible = $HIDE_IE ? false : true
- def self.visible
- return false if $HIDE_IE
- @@visible
- end
- def self.visible= x
- $HIDE_IE = nil
- @@visible = x
- end
+ def self.set_options options
+ options.each do |name, value|
+ send "#{name}=", value
+ end
+ end
+ # The globals $FAST_SPEED and $HIDE_IE are checked both at initialization
+ # and later, because they
+ # might be set after initialization. Setting them beforehand (e.g. from
+ # the command line) will affect the class, otherwise it is only a temporary
+ # effect
+ @@speed = $FAST_SPEED ? :fast : :slow
+ def self.speed
+ return :fast if $FAST_SPEED
+ @@speed
+ end
+ def self.speed= x
+ $FAST_SPEED = nil
+ @@speed = x
+ end
+ @@visible = $HIDE_IE ? false : true
+ def self.visible
+ return false if $HIDE_IE
+ @@visible
+ end
+ def self.visible= x
+ $HIDE_IE = nil
+ @@visible = x
+ end
@@zero_based_indexing = true
def self.zero_based_indexing= enabled
@@zero_based_indexing = enabled
end
@@ -200,24 +200,24 @@
# With IE#speed= :zippy, text fields will be entered at once, instead of
# character by character (default).
def speed= how_fast
case how_fast
when :zippy then
- @typingspeed = 0
- @pause_after_wait = 0.01
- @type_keys = false
- @speed = :fast
+ @typingspeed = 0
+ @pause_after_wait = 0.01
+ @type_keys = false
+ @speed = :fast
when :fast then
- @typingspeed = 0
- @pause_after_wait = 0.01
- @type_keys = true
- @speed = :fast
+ @typingspeed = 0
+ @pause_after_wait = 0.01
+ @type_keys = true
+ @speed = :fast
when :slow then
- @typingspeed = 0.08
- @pause_after_wait = 0.1
- @type_keys = true
- @speed = :slow
+ @typingspeed = 0.08
+ @pause_after_wait = 0.1
+ @type_keys = true
+ @speed = :slow
else
raise ArgumentError, "Invalid speed: #{how_fast}"
end
end
@@ -226,16 +226,16 @@
return @type_keys ? :fast : :zippy
end
# deprecated: use speed = :fast instead
def set_fast_speed
- self.speed = :fast
+ self.speed = :fast
end
# deprecated: use speed = :slow instead
def set_slow_speed
- self.speed = :slow
+ self.speed = :slow
end
def visible
@ie.visible
end
@@ -325,11 +325,11 @@
Watir::until_with_timeout do
ieTemp = IE._find how, what
end
rescue Watir::Wait::TimeoutError
raise NoMatchingWindowFoundException,
- "Unable to locate a window with #{how} of #{what}"
+ "Unable to locate a window with #{how} of #{what}"
end
@ie = ieTemp
end
private :attach_browser_window
@@ -338,11 +338,11 @@
raise "Not attached to a browser" if @ie.nil?
@hwnd ||= @ie.hwnd
end
attr_writer :hwnd
- # Are we attached to an open browser?
+ # Are we attached to an open browser?
def exists?
begin
!!(@ie.name =~ /Internet Explorer/)
rescue WIN32OLERuntimeError, NoMethodError
false
@@ -417,15 +417,14 @@
'#<%s:0x%x url=%s title=%s>' % [self.class, hash*2, url.inspect, title.inspect]
end
# Execute the given JavaScript string
def execute_script(source)
- document.parentWindow.eval(source.to_s)
+ escaped_src = source.to_s.gsub(/[\r\n']/) {|m| "\\#{m}"}
+ document.parentWindow.eval(escaped_src)
rescue WIN32OLERuntimeError, NoMethodError #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);"
+ 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