Class: Watir::IE

Inherits:
Object
  • Object
show all
Includes:
Container, Exception, PageContainer
Defined in:
lib/watir/process.rb,
lib/watir/ie-class.rb,
lib/watir/close_all.rb,
lib/watir/camel_case.rb,
lib/watir/ie-process.rb,
lib/watir/contrib/ie-new-process.rb

Defined Under Namespace

Classes: Process

Constant Summary collapse

READYSTATE_INTERACTIVE =

Used internally to determine when IE has finished loading a page

3
READYSTATE_COMPLETE =
4
HIGHLIGHT_COLOR =

The default color for highlighting objects as they are accessed.

'yellow'
EMPTY_TAG_NAME =

IE inserts some element whose tagName is empty and just acts as block level element Probably some IE method of cleaning things To pass the same to the xml parser we need to give some name to empty tagName

"DUMMY"
@@attach_timeout =

Maximum number of seconds to wait when attaching to a window

2.0
@@speed =

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

$FAST_SPEED ? :fast : :slow
@@visible =
$HIDE_IE ? false : true

Constants included from Win32

Win32::FindWindowEx, Win32::GW_CHILD, Win32::GW_ENABLEDPOPUP, Win32::GW_HWNDFIRST, Win32::GW_HWNDLAST, Win32::GW_HWNDNEXT, Win32::GW_HWNDPREV, Win32::GW_MAX, Win32::GW_OWNER, Win32::GetUnknown, Win32::GetWindow, Win32::IsWindow, Win32::User32

Instance Attribute Summary collapse

Attributes included from Container

#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PageContainer

#check_for_http_error, #contains_text, #enabled_popup, #html, #set_container, #show_frames, #text

Methods included from Win32

window_exists?

Methods included from Container

#area, #areas, #button, #buttons, #cell, #cells, #checkbox, #checkboxes, #dds, #divs, #dls, #dts, #element, #elements, #ems, #file_field, #file_fields, #form, #forms, #frame, #hidden, #hiddens, #image, #images, #labels, #link, #links, #lis, #locate_all_elements, #locate_input_element, #locate_tagged_element, #map, #maps, #modal_dialog, #popup, #pres, #ps, #radio, #radios, #row, #rows, #select_list, #select_lists, #set_container, #show_all_objects, #spans, #strongs, #table, #tables, #text_field, #text_fields

Constructor Details

#initialize(suppress_new_window = nil) ⇒ IE

Create an IE browser.



84
85
86
# File 'lib/watir/ie-class.rb', line 84

def initialize suppress_new_window=nil
  _new_window_init unless suppress_new_window
end

Instance Attribute Details

#down_load_timeObject (readonly)

The time, in seconds, it took for the new page to load after executing the the last command



65
66
67
# File 'lib/watir/ie-class.rb', line 65

def down_load_time
  @down_load_time
end

#hwndObject

Return the current window handle



306
307
308
309
# File 'lib/watir/ie-class.rb', line 306

def hwnd
  raise "Not attached to a browser" if @ie.nil?
  @hwnd ||= @ie.hwnd
end

#ieObject

the OLE Internet Explorer object



68
69
70
# File 'lib/watir/ie-class.rb', line 68

def ie
  @ie
end

#loggerObject

access to the logger object



71
72
73
# File 'lib/watir/ie-class.rb', line 71

def logger
  @logger
end

#process_idObject



18
19
20
# File 'lib/watir/contrib/ie-new-process.rb', line 18

def process_id
  @process_id ||= IEProcess.process_id_from_hwnd @ie.hwnd
end

#url_listObject (readonly)

this contains the list of unique urls that have been visited



74
75
76
# File 'lib/watir/ie-class.rb', line 74

def url_list
  @url_list
end

Class Method Details

._find(how, what) ⇒ Object



261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/watir/ie-class.rb', line 261

def self._find(how, what)
  ieTemp = nil
  IE.each do |ie|
    window = ie.ie

    case how
    when :url
      ieTemp = window if (what.matches(window.locationURL))
    when :title
      # normal windows explorer shells do not have document

      # note window.document will fail for "new" browsers

      begin
        title = window.locationname
        title = window.document.title
      rescue WIN32OLERuntimeError
      end
      ieTemp = window if what.matches(title)
    when :hwnd
      begin
        ieTemp = window if what == window.HWND
      rescue WIN32OLERuntimeError
      end
    else
      raise ArgumentError
    end
  end
  return ieTemp
end

.attach(how, what) ⇒ Object

Return a Watir::IE object for an existing IE window. Window can be referenced by url, title, or window handle. Second argument can be either a string or a regular expression in the case of of :url or :title. IE.attach(:url, ‘www.google.com’) IE.attach(:title, ‘Google’) IE.attach(:hwnd, 528140) This method will not work when Watir/Ruby is run under a service (instead of a user).



142
143
144
145
146
# File 'lib/watir/ie-class.rb', line 142

def self.attach how, what
  ie = new true # don't create window

  ie._attach_init(how, what)
  ie
end

.attach_timeoutObject

default value



9
10
11
# File 'lib/watir/ie-class.rb', line 9

def self.attach_timeout
  @@attach_timeout
end

.attach_timeout=(timeout) ⇒ Object



12
13
14
# File 'lib/watir/ie-class.rb', line 12

def self.attach_timeout=(timeout)
  @@attach_timeout = timeout
end

.bind(window) ⇒ Object

Return an IE object that wraps the given window, typically obtained from Shell.Application.windows.



157
158
159
160
161
162
# File 'lib/watir/ie-class.rb', line 157

def self.bind window
  ie = new true
  ie.ie = window
  ie.initialize_options
  ie
end

.close_allObject

close all ie browser windows



6
7
8
# File 'lib/watir/close_all.rb', line 6

def self.close_all
  close_all_but nil
end

.eachObject

Yields to the window and its hwnd.



237
238
239
240
241
242
243
244
245
246
# File 'lib/watir/ie-class.rb', line 237

def self.each
  shell = WIN32OLE.new('Shell.Application')
  shell.Windows.each do |window|
    next unless (window.path =~ /Internet Explorer/ rescue false)
    next unless (hwnd = window.hwnd rescue false)
    ie = IE.bind(window)
    ie.hwnd = hwnd
    yield ie
  end
end

.find(how, what) ⇒ Object

return internet explorer instance as specified. if none is found, return nil. arguments:

:url, url -- the URL of the IE browser window
:title, title -- the title of the browser page
:hwnd, hwnd -- the window handle of the browser window.

This method will not work when Watir/Ruby is run under a service (instead of a user).



256
257
258
259
# File 'lib/watir/ie-class.rb', line 256

def self.find(how, what)
  ie_ole = IE._find(how, what)
  IE.bind ie_ole if ie_ole
end

.new_processObject

Create a new IE window in a new process. This method will not work when Watir/Ruby is run under a service (instead of a user).



111
112
113
114
115
# File 'lib/watir/ie-class.rb', line 111

def self.new_process
  ie = new true
  ie._new_process_init
  ie
end

.new_windowObject

Create a new IE window. Works just like IE.new in Watir 1.4.



77
78
79
80
81
# File 'lib/watir/ie-class.rb', line 77

def self.new_window
  ie = new true
  ie._new_window_init
  ie
end

.optionsObject

Return the options used when creating new instances of IE. BUG: this interface invites misunderstanding/misuse such as IE.options = :zippy]



18
19
20
# File 'lib/watir/ie-class.rb', line 18

def self.options
{:speed => self.speed, :visible => self.visible, :attach_timeout => self.attach_timeout}
end

.process_countObject

Returns the number of IEXPLORE processes currently running.



16
17
18
# File 'lib/watir/process.rb', line 16

def self.process_count
  Watir::Process.count 'iexplore.exe'
end

.set_options(options) ⇒ Object

set values for options used when creating new instances of IE.



22
23
24
25
26
# File 'lib/watir/ie-class.rb', line 22

def self.set_options options
  options.each do |name, value|
    send "#{name}=", value
  end
end

.speedObject



33
34
35
36
# File 'lib/watir/ie-class.rb', line 33

def self.speed
  return :fast if $FAST_SPEED
  @@speed
end

.speed=(x) ⇒ Object



37
38
39
40
# File 'lib/watir/ie-class.rb', line 37

def self.speed= x
  $FAST_SPEED = nil
  @@speed = x
end

.start(url = nil) ⇒ Object

Create a new IE Window, starting at the specified url. If no url is given, start empty.



96
97
98
# File 'lib/watir/ie-class.rb', line 96

def self.start url=nil
  start_window url
end

.start_process(url = nil) ⇒ Object

Create a new IE window in a new process, starting at the specified URL. Same as IE.start.



127
128
129
130
131
# File 'lib/watir/ie-class.rb', line 127

def self.start_process url=nil
  ie = new_process
  ie.goto url if url
  ie
end

.start_window(url = nil) ⇒ Object

Create a new IE window, starting at the specified url. If no url is given, start empty. Works like IE.start in Watir 1.4.



102
103
104
105
106
# File 'lib/watir/ie-class.rb', line 102

def self.start_window url=nil
  ie = new_window
  ie.goto url if url
  ie
end

.visibleObject



42
43
44
45
# File 'lib/watir/ie-class.rb', line 42

def self.visible
  return false if $HIDE_IE
  @@visible
end

.visible=(x) ⇒ Object



46
47
48
49
# File 'lib/watir/ie-class.rb', line 46

def self.visible= x
  $HIDE_IE = nil
  @@visible = x
end

Instance Method Details

#_attach_init(how, what) ⇒ Object

this method is used internally to attach to an existing window



149
150
151
152
153
# File 'lib/watir/ie-class.rb', line 149

def _attach_init how, what
  attach_browser_window how, what
  initialize_options
  wait
end

#_new_process_initObject



117
118
119
120
121
122
123
# File 'lib/watir/ie-class.rb', line 117

def _new_process_init
  iep = Process.start
  @ie = iep.window
  @process_id = iep.process_id
  initialize_options
  goto 'about:blank'
end

#_new_window_initObject



88
89
90
91
92
# File 'lib/watir/ie-class.rb', line 88

def _new_window_init
  create_browser_window
  initialize_options
  goto 'about:blank' # this avoids numerous problems caused by lack of a document

end

#add_checker(checker) ⇒ Object

this method is used to add an error checker that gets executed on every page load

  • checker Proc Object, that contains the code to be run



535
536
537
# File 'lib/watir/ie-class.rb', line 535

def add_checker(checker)
  @error_checkers << checker
end

#attach_commandObject



1004
1005
1006
# File 'lib/watir/ie-class.rb', line 1004

def attach_command
  "Watir::IE.attach(:hwnd, #{hwnd})"
end

#backObject

Go to the previous page - the same as clicking the browsers back button an WIN32OLERuntimeError exception is raised if the browser cant go back



360
361
362
363
# File 'lib/watir/ie-class.rb', line 360

def back
  @ie.GoBack
  wait
end

#bring_to_frontObject

Make the window come to the front



424
425
426
# File 'lib/watir/ie-class.rb', line 424

def bring_to_front
  autoit.WinActivate title, ''
end

#clear_url_listObject

clear the list of urls that we have visited



391
392
393
# File 'lib/watir/ie-class.rb', line 391

def clear_url_list
  @url_list.clear
end

#closeObject

Closes the Browser



396
397
398
399
400
401
402
403
404
405
406
# File 'lib/watir/ie-class.rb', line 396

def close
  return unless exists?
  @closing = true
  @ie.stop
  wait rescue nil
  chwnd = @ie.hwnd.to_i
  @ie.quit
  while Win32API.new("user32","IsWindow", 'L', 'L').Call(chwnd) == 1
    sleep 0.3
  end
end

#close_modalObject

close modal dialog. unlike IE#modal_dialog.close, does not wait for dialog to appear and does not raise exception if no window is found. returns true if modal was found and close, otherwise false



25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/watir/close_all.rb', line 25

def close_modal
  begin
    original_attach_timeout = IE.attach_timeout
    IE.attach_timeout = 0
    self.modal_dialog.close
    true
  rescue NoMatchingWindowFoundException, TimeOutException
    false
  ensure
    IE.attach_timeout = original_attach_timeout
  end
end

#close_othersObject

find other ie browser windows and close them



10
11
12
# File 'lib/watir/close_all.rb', line 10

def close_others
  IE.close_all_but self
end

#dirObject



449
450
451
# File 'lib/watir/ie-class.rb', line 449

def dir
  return File.expand_path(File.dirname(__FILE__))
end

#disable_checker(checker) ⇒ Object

this allows a checker to be disabled

  • checker Proc Object, the checker that is to be disabled



541
542
543
# File 'lib/watir/ie-class.rb', line 541

def disable_checker(checker)
  @error_checkers.delete(checker)
end

#documentObject Also known as: getDocument

Return the current document



458
459
460
# File 'lib/watir/ie-class.rb', line 458

def document
  return @ie.document
end

#element_by_xpath(xpath) ⇒ Object

return the first element that matches the xpath



896
897
898
899
900
# File 'lib/watir/ie-class.rb', line 896

def element_by_xpath(xpath)
  temp = elements_by_xpath(xpath)
  temp = temp[0] if temp
  return temp
end

#elements_by_xpath(xpath) ⇒ Object

execute xpath and return an array of elements



903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
# File 'lib/watir/ie-class.rb', line 903

def elements_by_xpath(xpath)
  doc = xmlparser_document_object
  modifiedXpath = ""
  selectedElements = Array.new

  # strip any trailing slash from the xpath expression (as used in watir unit tests)

  xpath.chop! unless (/\/$/ =~ xpath).nil?

  doc.xpath(xpath).each do |element|
    modifiedXpath = element.path
    temp = element_by_absolute_xpath(modifiedXpath) # temp = a DOM/COM element

    selectedElements << temp if temp != nil
  end
  #puts selectedElements.length

  if selectedElements.length == 0
    return nil
  else
    return selectedElements
  end
end

#execute_script(source) ⇒ Object

Execute the given JavaScript string



384
385
386
387
388
# File 'lib/watir/ie-class.rb', line 384

def execute_script(source)
  document.parentWindow.eval(source.to_s)
rescue WIN32OLERuntimeError
  document.parentWindow.execScript(source.to_s)
end

#exists?Boolean Also known as: exist?

Are we attached to an open browser?

Returns:

  • (Boolean)


313
314
315
316
317
318
319
320
# File 'lib/watir/ie-class.rb', line 313

def exists?
  return false if @closing
  begin
    @ie.name =~ /Internet Explorer/
  rescue WIN32OLERuntimeError
    false
  end
end

#focusObject

Gives focus to the frame



694
695
696
697
# File 'lib/watir/ie-class.rb', line 694

def focus
  document.activeElement.blur
  document.focus
end

#forwardObject

Go to the next page - the same as clicking the browsers forward button an WIN32OLERuntimeError exception is raised if the browser cant go forward



367
368
369
370
# File 'lib/watir/ie-class.rb', line 367

def forward
  @ie.GoForward
  wait
end

#front?Boolean

Returns:

  • (Boolean)


428
429
430
# File 'lib/watir/ie-class.rb', line 428

def front?
  1 == autoit.WinActive(title, '')
end

#getIEObject



24
# File 'lib/watir/camel_case.rb', line 24

def   getIE; @ie; end

#goto(url) ⇒ Object

Navigate to the specified URL.

* url - string - the URL to navigate to


352
353
354
355
356
# File 'lib/watir/ie-class.rb', line 352

def goto(url)
  @ie.navigate(url)
  wait
  return @down_load_time
end

#initialize_optionsObject



169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/watir/ie-class.rb', line 169

def initialize_options
  self.visible = IE.visible
  self.speed = IE.speed

  @ole_object = nil
  @page_container = self
  @error_checkers = []
  @activeObjectHighLightColor = HIGHLIGHT_COLOR


  @logger = DefaultLogger.new
  @url_list = []
end

#inspectObject



379
380
381
# File 'lib/watir/ie-class.rb', line 379

def inspect
  '#<%s:0x%x url=%s title=%s>' % [self.class, hash*2, url.inspect, title.inspect]
end

#killObject



22
23
24
25
# File 'lib/watir/contrib/ie-new-process.rb', line 22

def kill
  iep = IEProcess.new process_id
  iep.stop
end

#log(what) ⇒ Object



328
329
330
# File 'lib/watir/ie-class.rb', line 328

def log(what)
  @logger.debug(what) if @logger
end

#maximizeObject

Maximize the window (expands to fill the screen)



409
410
411
# File 'lib/watir/ie-class.rb', line 409

def maximize
  set_window_state :SW_MAXIMIZE
end

#minimizeObject

Minimize the window (appears as icon on taskbar)



414
415
416
# File 'lib/watir/ie-class.rb', line 414

def minimize
  set_window_state :SW_MINIMIZE
end

#refreshObject

Refresh the current page - the same as clicking the browsers refresh button an WIN32OLERuntimeError exception is raised if the browser cant refresh



374
375
376
377
# File 'lib/watir/ie-class.rb', line 374

def refresh
  @ie.refresh2(3)
  wait
end

#restoreObject

Restore the window (after minimizing or maximizing)



419
420
421
# File 'lib/watir/ie-class.rb', line 419

def restore
  set_window_state :SW_RESTORE
end

#run_error_checksObject

this method runs the predefined error checks



529
530
531
# File 'lib/watir/ie-class.rb', line 529

def run_error_checks
  @error_checkers.each { |e| e.call(self) }
end

#send_keys(key_string) ⇒ Object

Send key events to IE window. See www.autoitscript.com/autoit3/docs/appendix/SendKeys.htm for complete documentation on keys supported and syntax.



444
445
446
447
# File 'lib/watir/ie-class.rb', line 444

def send_keys(key_string)
  autoit.WinActivate title
  autoit.Send key_string
end

#set_fast_speedObject

deprecated: use speed = :fast instead



217
218
219
# File 'lib/watir/ie-class.rb', line 217

def set_fast_speed
  self.speed = :fast
end

#set_logger(logger) ⇒ Object

deprecated: use logger= instead



324
325
326
# File 'lib/watir/ie-class.rb', line 324

def set_logger(logger)
  @logger = logger
end

#set_slow_speedObject

deprecated: use speed = :slow instead



222
223
224
# File 'lib/watir/ie-class.rb', line 222

def set_slow_speed
  self.speed = :slow
end

#show_activeObject Also known as: showActive

this method shows the name, id etc of the object that is currently active - ie the element that has focus its mostly used in irb when creating a script



620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
# File 'lib/watir/ie-class.rb', line 620

def show_active
  s = ""

  current = document.activeElement
  begin
    s += current.invoke("type").to_s.ljust(16)
  rescue
  end
  props = ["name", "id", "value", "alt", "src", "innerText", "href"]
  props.each do |prop|
    begin
      p = current.invoke(prop)
      s += "  " + "#{prop}=#{p}".to_s.ljust(18)
    rescue
      #this object probably doesnt have this property

    end
  end
  s += "\n"
end

#show_divsObject

this method shows all the divs availble in the document



641
642
643
644
645
646
647
648
649
# File 'lib/watir/ie-class.rb', line 641

def show_divs
  divs = document.getElementsByTagName("DIV")
  puts "Found #{divs.length} div tags"
  index = 1
  divs.each do |d|
    puts "#{index}  id=#{d.invoke('id')}      class=#{d.invoke("className")}"
    index += 1
  end
end

#show_formsObject Also known as: showForms

Show all forms displays all the forms that are on a web page.



550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
# File 'lib/watir/ie-class.rb', line 550

def show_forms
  if allForms = document.forms
    count = allForms.length
    puts "There are #{count} forms"
    for i in 0..count-1 do
      wrapped = FormWrapper.new(allForms.item(i))
      puts "Form name: #{wrapped.name}"
      puts "       id: #{wrapped.id}"
      puts "   method: #{wrapped.method}"
      puts "   action: #{wrapped.action}"
    end
  else
    puts "No forms"
  end
end

#show_imagesObject Also known as: showImages

this method shows all the images availble in the document



567
568
569
570
571
572
573
574
575
576
577
# File 'lib/watir/ie-class.rb', line 567

def show_images
  doc = document
  index = 1
  doc.images.each do |l|
    puts "image: name: #{l.name}"
    puts "         id: #{l.invoke("id")}"
    puts "        src: #{l.src}"
    puts "      index: #{index}"
    index += 1
  end
end

#show_labelsObject



683
684
685
686
687
688
689
690
691
# File 'lib/watir/ie-class.rb', line 683

def show_labels
  labels = document.getElementsByTagName("LABEL")
  puts "Found #{labels.length} label tags"
  index = 1
  labels.each do |d|
    puts "#{index}  text=#{d.invoke('innerText')}      class=#{d.invoke("className")}  for=#{d.invoke("htmlFor")}"
    index += 1
  end
end

this method shows all the links availble in the document



580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
# File 'lib/watir/ie-class.rb', line 580

def show_links
  props = ["name", "id", "href"]
  print_sizes = [12, 12, 60]
  doc = document
  index = 0
  text_size = 60
  # draw the table header

  s = "index".ljust(6)
  props.each_with_index do |p, i|
    s += p.ljust(print_sizes[i])
  end
  s += "text/src".ljust(text_size)
  s += "\n"

  # now get the details of the links

  doc.links.each do |n|
    index += 1
    s = s + index.to_s.ljust(6)
    props.each_with_index do |prop, i|
      printsize = print_sizes[i]
      begin
        p = n.invoke(prop)
        temp_var = "#{p}".to_s.ljust(printsize)
      rescue
        # this object probably doesnt have this property

        temp_var = "".to_s.ljust(printsize)
      end
      s += temp_var
    end
    s += n.innerText
    if n.getElementsByTagName("IMG").length > 0
      s += " / " + n.getElementsByTagName("IMG").item(0).src
    end
    s += "\n"
  end
  puts s
end

#show_presObject



662
663
664
665
666
667
668
669
670
# File 'lib/watir/ie-class.rb', line 662

def show_pres
  pres = document.getElementsByTagName("PRE")
  puts "Found #{ pres.length } pre tags"
  index = 1
  pres.each do |d|
    puts "#{index}   id=#{d.invoke('id')}      class=#{d.invoke("className")}"
    index+=1
  end
end

#show_spansObject

this method shows all the spans availble in the document



673
674
675
676
677
678
679
680
681
# File 'lib/watir/ie-class.rb', line 673

def show_spans
  spans = document.getElementsByTagName("SPAN")
  puts "Found #{spans.length} span tags"
  index = 1
  spans.each do |d|
    puts "#{index}   id=#{d.invoke('id')}      class=#{d.invoke("className")}"
    index += 1
  end
end

#show_tablesObject

this method is used to show all the tables that are available



652
653
654
655
656
657
658
659
660
# File 'lib/watir/ie-class.rb', line 652

def show_tables
  tables = document.getElementsByTagName("TABLE")
  puts "Found #{tables.length} tables"
  index = 1
  tables.each do |d|
    puts "#{index}  id=#{d.invoke('id')}      rows=#{d.rows.length}   columns=#{begin d.rows["0"].cells.length; rescue; end}"
    index += 1
  end
end

#speedObject



211
212
213
214
# File 'lib/watir/ie-class.rb', line 211

def speed
  return @speed if @speed == :slow
  return @type_keys ? :fast : :zippy
end

#speed=(how_fast) ⇒ Object

Specifies the speed that commands will be executed at. Choices are:

  • :slow (default)

  • :fast

  • :zippy

With IE#speed= :zippy, text fields will be entered at once, instead of character by character (default).



189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/watir/ie-class.rb', line 189

def speed= how_fast
  case how_fast
  when :zippy then
   @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
  when :slow then
   @typingspeed = 0.08
   @pause_after_wait = 0.1
   @type_keys = true
   @speed = :slow
  else
    raise ArgumentError, "Invalid speed: #{how_fast}"
  end
end

#statusObject Also known as: getStatus

Return the status of the window, typically from the status bar at the bottom.



342
343
344
# File 'lib/watir/ie-class.rb', line 342

def status
  return @ie.statusText
end

#titleObject

Return the title of the document



337
338
339
# File 'lib/watir/ie-class.rb', line 337

def title
  @ie.document.title
end

#urlObject

returns the current url, as displayed in the address bar of the browser



463
464
465
# File 'lib/watir/ie-class.rb', line 463

def url
  return @ie.LocationURL
end

#visibleObject



226
227
228
# File 'lib/watir/ie-class.rb', line 226

def visible
  @ie.visible
end

#visible=(boolean) ⇒ Object



229
230
231
# File 'lib/watir/ie-class.rb', line 229

def visible=(boolean)
  @ie.visible = boolean if boolean != @ie.visible
end

#wait(no_sleep = false) ⇒ Object Also known as: waitForIE

Block execution until the page has loaded.

Will raise Timeout::Error if page hasn’t been loaded within 5 minutes.

nodoc

Note: This code needs to be prepared for the ie object to be closed at any moment!



477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/watir/ie-class.rb', line 477

def wait(no_sleep=false)
  @xml_parser_doc = nil
  @down_load_time = 0.0
  interval = 0.05
  start_load_time = Time.now

  Timeout::timeout(5*60) do
    begin
      while @ie.busy
        sleep interval
      end

      until [READYSTATE_INTERACTIVE, READYSTATE_COMPLETE].include?(@ie.readyState)
        sleep interval
      end

      until @ie.document
        sleep interval
      end

      documents_to_wait_for = [@ie.document]
    rescue WIN32OLERuntimeError # IE window must have been closed

      @down_load_time = Time.now - start_load_time
      return @down_load_time
    end

    while doc = documents_to_wait_for.shift
      begin
        until ["interactive", "complete"].include?(doc.readyState)
          sleep interval
        end
        @url_list << doc.location.href unless @url_list.include?(doc.location.href)
        doc.frames.length.times do |n|
          begin
            documents_to_wait_for << doc.frames[n.to_s].document
          rescue WIN32OLERuntimeError, NoMethodError
          end
        end
      rescue WIN32OLERuntimeError
      end
    end
  end

  @down_load_time = Time.now - start_load_time
  run_error_checks
  sleep @pause_after_wait unless no_sleep
  @down_load_time
end

#xmlparser_document_objectObject

Functions written for using xpath for getting the elements.



701
702
703
704
705
706
# File 'lib/watir/ie-class.rb', line 701

def xmlparser_document_object
  if @xml_parser_doc == nil
    create_xml_parser_doc
  end
  return @xml_parser_doc
end