Class: Watir::IE
- Inherits:
-
Object
- Object
- Watir::IE
- Includes:
- Exception, WaitHelper, Container, 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
- READYSTATES =
Used internally to determine when IE has finished loading a page
{: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
- @@zero_based_indexing =
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
-
#down_load_time ⇒ Object
readonly
The time, in seconds, it took for the new page to load after executing the the last command.
-
#hwnd ⇒ Object
Return the current window handle.
-
#ie ⇒ Object
the OLE Internet Explorer object.
-
#logger ⇒ Object
access to the logger object.
- #process_id ⇒ Object
-
#url_list ⇒ Object
readonly
this contains the list of unique urls that have been visited.
Attributes included from Container
#activeObjectHighLightColor, #page_container, #type_keys, #typingspeed
Class Method Summary collapse
- ._find(how, what) ⇒ Object
-
.attach(how, what) ⇒ Object
Return a Watir::IE object for an existing IE window.
-
.attach_timeout ⇒ Object
default value.
- .attach_timeout=(timeout) ⇒ Object
- .base_index ⇒ Object
-
.bind(window) ⇒ Object
Return an IE object that wraps the given window, typically obtained from Shell.Application.windows.
-
.close_all ⇒ Object
close all ie browser windows.
-
.each ⇒ Object
Yields successively to each IE window on the current desktop.
-
.find(how, what) ⇒ Object
return internet explorer instance as specified.
-
.new_process ⇒ Object
Create a new IE window in a new process.
-
.new_window ⇒ Object
Create a new IE window.
-
.options ⇒ Object
Return the options used when creating new instances of IE.
-
.process_count ⇒ Object
Returns the number of IEXPLORE processes currently running.
-
.set_options(options) ⇒ Object
set values for options used when creating new instances of IE.
- .speed ⇒ Object
- .speed=(x) ⇒ Object
-
.start(url = nil) ⇒ Object
Create a new IE Window, starting at the specified url.
-
.start_process(url = nil) ⇒ Object
Create a new IE window in a new process, starting at the specified URL.
-
.start_window(url = nil) ⇒ Object
Create a new IE window, starting at the specified url.
- .version ⇒ Object
- .version_parts ⇒ Object
- .visible ⇒ Object
- .visible=(x) ⇒ Object
- .zero_based_indexing ⇒ Object
- .zero_based_indexing=(enabled) ⇒ Object
Instance Method Summary collapse
-
#_attach_init(how, what) ⇒ Object
this method is used internally to attach to an existing window.
- #_new_process_init ⇒ Object
- #_new_window_init ⇒ Object
-
#activate ⇒ Object
(also: #bring_to_front)
Make the window come to the front.
- #active? ⇒ Boolean (also: #front?)
-
#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.
- #attach_command ⇒ Object
- #autoit ⇒ Object
-
#back ⇒ Object
Go to the previous page - the same as clicking the browsers back button an WIN32OLERuntimeError exception is raised if the browser cant go back.
-
#clear_url_list ⇒ Object
clear the list of urls that we have visited.
-
#close ⇒ Object
Closes the Browser.
-
#close_modal ⇒ Object
close modal dialog.
-
#close_others ⇒ Object
find other ie browser windows and close them.
- #dir ⇒ Object
-
#disable_checker(checker) ⇒ Object
this allows a checker to be disabled * checker Proc Object, the checker that is to be disabled.
-
#document ⇒ Object
(also: #getDocument)
Return the current document.
-
#document_mode ⇒ Object
The document standards mode used by IE can be overridden in the html with: <meta http-equiv=“x-ua-compatible” content=“IE=8”>.
-
#element_by_css(selector) ⇒ Object
return the first (ole object) element that matches the css selector.
-
#element_by_xpath(xpath) ⇒ Object
return the first element that matches the xpath.
-
#elements_by_css(selector) ⇒ Object
execute css selector and return an array of (ole object) elements.
-
#elements_by_xpath(xpath) ⇒ Object
execute xpath and return an array of elements.
-
#execute_script(source) ⇒ Object
Execute the given JavaScript string.
-
#exists? ⇒ Boolean
(also: #exist?)
Are we attached to an open browser?.
-
#focus ⇒ Object
Gives focus to the frame.
-
#forward ⇒ Object
Go to the next page - the same as clicking the browsers forward button an WIN32OLERuntimeError exception is raised if the browser cant go forward.
- #getIE ⇒ Object
-
#goto(url) ⇒ Object
Navigate to the specified URL.
-
#initialize(suppress_new_window = nil) ⇒ IE
constructor
Create an IE browser.
- #initialize_options ⇒ Object
- #inspect ⇒ Object
- #kill ⇒ Object
- #log(what) ⇒ Object
-
#maximize ⇒ Object
Maximize the window (expands to fill the screen).
-
#minimize ⇒ Object
Minimize the window (appears as icon on taskbar).
- #minimized? ⇒ Boolean
- #rautomation ⇒ Object
-
#refresh ⇒ Object
Refresh the current page - the same as clicking the browsers refresh button an WIN32OLERuntimeError exception is raised if the browser cant refresh.
-
#restore ⇒ Object
Restore the window (after minimizing or maximizing).
-
#run_error_checks ⇒ Object
this method runs the predefined error checks.
-
#send_keys(key_string) ⇒ Object
Activates the window and sends keys to it.
-
#set_fast_speed ⇒ Object
deprecated: use speed = :fast instead.
-
#set_logger(logger) ⇒ Object
deprecated: use logger= instead.
-
#set_slow_speed ⇒ Object
deprecated: use speed = :slow instead.
-
#show_active ⇒ Object
(also: #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.
-
#show_divs ⇒ Object
this method shows all the divs availble in the document.
-
#show_forms ⇒ Object
(also: #showForms)
Show all forms displays all the forms that are on a web page.
-
#show_images ⇒ Object
(also: #showImages)
this method shows all the images availble in the document.
- #show_labels ⇒ Object
-
#show_links ⇒ Object
(also: #showLinks)
this method shows all the links availble in the document.
- #show_pres ⇒ Object
-
#show_spans ⇒ Object
this method shows all the spans availble in the document.
-
#show_tables ⇒ Object
this method is used to show all the tables that are available.
- #speed ⇒ Object
-
#speed=(how_fast) ⇒ Object
Specifies the speed that commands will be executed at.
-
#status ⇒ Object
(also: #getStatus)
Return the status of the window, typically from the status bar at the bottom.
-
#title ⇒ Object
Return the title of the document.
-
#url ⇒ Object
returns the current url, as displayed in the address bar of the browser.
- #visible ⇒ Object
- #visible=(boolean) ⇒ Object
-
#wait(no_sleep = false) ⇒ Object
(also: #waitForIE)
Block execution until the page has loaded.
-
#xmlparser_document_object ⇒ Object
Functions written for using xpath for getting the elements.
Methods included from PageContainer
#check_for_http_error, #contains_text, #enabled_popup, #html, #set_container, #show_frames, #text
Methods included from Win32
Methods included from Container
#__ole_inner_elements, #input_element_locator, #locator_for, #set_container, #show_all_objects, #tagged_element_locator
Constructor Details
#initialize(suppress_new_window = nil) ⇒ IE
Create an IE browser.
97 98 99 |
# File 'lib/watir/ie-class.rb', line 97 def initialize suppress_new_window=nil _new_window_init unless suppress_new_window end |
Instance Attribute Details
#down_load_time ⇒ Object (readonly)
The time, in seconds, it took for the new page to load after executing the the last command
78 79 80 |
# File 'lib/watir/ie-class.rb', line 78 def down_load_time @down_load_time end |
#hwnd ⇒ Object
Return the current window handle
337 338 339 340 |
# File 'lib/watir/ie-class.rb', line 337 def hwnd raise "Not attached to a browser" if @ie.nil? @hwnd ||= @ie.hwnd end |
#ie ⇒ Object
the OLE Internet Explorer object
81 82 83 |
# File 'lib/watir/ie-class.rb', line 81 def ie @ie end |
#logger ⇒ Object
access to the logger object
84 85 86 |
# File 'lib/watir/ie-class.rb', line 84 def logger @logger end |
#process_id ⇒ Object
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_list ⇒ Object (readonly)
this contains the list of unique urls that have been visited
87 88 89 |
# File 'lib/watir/ie-class.rb', line 87 def url_list @url_list end |
Class Method Details
._find(how, what) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/watir/ie-class.rb', line 292 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).
155 156 157 158 159 |
# File 'lib/watir/ie-class.rb', line 155 def self.attach how, what ie = new true # don't create window ie._attach_init(how, what) ie end |
.attach_timeout ⇒ Object
default value
10 11 12 |
# File 'lib/watir/ie-class.rb', line 10 def self.attach_timeout @@attach_timeout end |
.attach_timeout=(timeout) ⇒ Object
13 14 15 |
# File 'lib/watir/ie-class.rb', line 13 def self.attach_timeout=(timeout) @@attach_timeout = timeout end |
.base_index ⇒ Object
61 62 63 |
# File 'lib/watir/ie-class.rb', line 61 def self.base_index self.zero_based_indexing ? 0 : 1 end |
.bind(window) ⇒ Object
Return an IE object that wraps the given window, typically obtained from Shell.Application.windows.
170 171 172 173 174 175 |
# File 'lib/watir/ie-class.rb', line 170 def self.bind window ie = new true ie.ie = window ie. ie end |
.close_all ⇒ Object
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 |
.each ⇒ Object
Yields successively to each IE window on the current desktop. Takes a block. This method will not work when Watir/Ruby is run under a service (instead of a user). Yields to the window and its hwnd.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
# File 'lib/watir/ie-class.rb', line 250 def self.each shell = WIN32OLE.new('Shell.Application') ie_browsers = [] 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 ie_browsers << ie end ie_browsers.each do |ie| 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).
287 288 289 290 |
# File 'lib/watir/ie-class.rb', line 287 def self.find(how, what) ie_ole = IE._find(how, what) IE.bind ie_ole if ie_ole end |
.new_process ⇒ Object
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).
124 125 126 127 128 |
# File 'lib/watir/ie-class.rb', line 124 def self.new_process ie = new true ie._new_process_init ie end |
.new_window ⇒ Object
Create a new IE window. Works just like IE.new in Watir 1.4.
90 91 92 93 94 |
# File 'lib/watir/ie-class.rb', line 90 def self.new_window ie = new true ie._new_window_init ie end |
.options ⇒ Object
Return the options used when creating new instances of IE. BUG: this interface invites misunderstanding/misuse such as IE.options = :zippy]
19 20 21 |
# File 'lib/watir/ie-class.rb', line 19 def self. {:speed => self.speed, :visible => self.visible, :attach_timeout => self.attach_timeout, :zero_based_indexing => self.zero_based_indexing} end |
.process_count ⇒ Object
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.
23 24 25 26 27 |
# File 'lib/watir/ie-class.rb', line 23 def self. .each do |name, value| send "#{name}=", value end end |
.speed ⇒ Object
34 35 36 37 |
# File 'lib/watir/ie-class.rb', line 34 def self.speed return :fast if $FAST_SPEED @@speed end |
.speed=(x) ⇒ Object
38 39 40 41 |
# File 'lib/watir/ie-class.rb', line 38 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.
109 110 111 |
# File 'lib/watir/ie-class.rb', line 109 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.
140 141 142 143 144 |
# File 'lib/watir/ie-class.rb', line 140 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.
115 116 117 118 119 |
# File 'lib/watir/ie-class.rb', line 115 def self.start_window url=nil ie = new_window ie.goto url if url ie end |
.version ⇒ Object
265 266 267 268 269 270 271 272 273 |
# File 'lib/watir/ie-class.rb', line 265 def self.version @ie_version ||= begin require 'win32/registry' ::Win32::Registry::HKEY_LOCAL_MACHINE.open("SOFTWARE\\Microsoft\\Internet Explorer") do |ie_key| ie_key.read('Version').last end # OR: ::WIN32OLE.new("WScript.Shell").RegRead("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer\\Version") end end |
.version_parts ⇒ Object
275 276 277 |
# File 'lib/watir/ie-class.rb', line 275 def self.version_parts version.split('.') end |
.visible ⇒ Object
43 44 45 46 |
# File 'lib/watir/ie-class.rb', line 43 def self.visible return false if $HIDE_IE @@visible end |
.visible=(x) ⇒ Object
47 48 49 50 |
# File 'lib/watir/ie-class.rb', line 47 def self.visible= x $HIDE_IE = nil @@visible = x end |
.zero_based_indexing ⇒ Object
57 58 59 |
# File 'lib/watir/ie-class.rb', line 57 def self.zero_based_indexing @@zero_based_indexing end |
.zero_based_indexing=(enabled) ⇒ Object
53 54 55 |
# File 'lib/watir/ie-class.rb', line 53 def self.zero_based_indexing= enabled @@zero_based_indexing = enabled end |
Instance Method Details
#_attach_init(how, what) ⇒ Object
this method is used internally to attach to an existing window
162 163 164 165 166 |
# File 'lib/watir/ie-class.rb', line 162 def _attach_init how, what attach_browser_window how, what wait end |
#_new_process_init ⇒ Object
130 131 132 133 134 135 136 |
# File 'lib/watir/ie-class.rb', line 130 def _new_process_init iep = Process.start @ie = iep.window @process_id = iep.process_id goto 'about:blank' end |
#_new_window_init ⇒ Object
101 102 103 104 105 |
# File 'lib/watir/ie-class.rb', line 101 def _new_window_init create_browser_window goto 'about:blank' # this avoids numerous problems caused by lack of a document end |
#activate ⇒ Object Also known as: bring_to_front
Make the window come to the front
476 477 478 |
# File 'lib/watir/ie-class.rb', line 476 def activate rautomation.activate end |
#active? ⇒ Boolean Also known as: front?
481 482 483 |
# File 'lib/watir/ie-class.rb', line 481 def active? rautomation.active? 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
595 596 597 |
# File 'lib/watir/ie-class.rb', line 595 def add_checker(checker) @error_checkers << checker end |
#attach_command ⇒ Object
1081 1082 1083 |
# File 'lib/watir/ie-class.rb', line 1081 def attach_command "Watir::IE.attach(:hwnd, #{hwnd})" end |
#autoit ⇒ Object
491 492 493 494 495 |
# File 'lib/watir/ie-class.rb', line 491 def autoit Kernel.warn "Usage of Watir::IE#autoit method is DEPRECATED! Use Watir::IE#rautomation method instead. Refer to https://github.com/jarmo/RAutomation for updating your scripts." @autoit ||= ::RAutomation::Window.new(:hwnd => hwnd, :adapter => :autoit) @autoit end |
#back ⇒ Object
Go to the previous page - the same as clicking the browsers back button an WIN32OLERuntimeError exception is raised if the browser cant go back
397 398 399 400 |
# File 'lib/watir/ie-class.rb', line 397 def back @ie.GoBack wait end |
#clear_url_list ⇒ Object
clear the list of urls that we have visited
436 437 438 |
# File 'lib/watir/ie-class.rb', line 436 def clear_url_list @url_list.clear end |
#close ⇒ Object
Closes the Browser
441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'lib/watir/ie-class.rb', line 441 def close return unless exists? @ie.stop wait rescue nil chwnd = @ie.hwnd.to_i @ie.quit t = Time.now while exists? # just in case to avoid possible endless loop if failing to close some # window or tab break if Time.now - t > 10 sleep 0.3 end end |
#close_modal ⇒ Object
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 |
# File 'lib/watir/close_all.rb', line 25 def close_modal while self.modal_dialog.exists?(0) do self.modal_dialog.close end end |
#close_others ⇒ Object
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 |
#dir ⇒ Object
509 510 511 |
# File 'lib/watir/ie-class.rb', line 509 def dir return File.(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
601 602 603 |
# File 'lib/watir/ie-class.rb', line 601 def disable_checker(checker) @error_checkers.delete(checker) end |
#document ⇒ Object Also known as: getDocument
Return the current document
518 519 520 |
# File 'lib/watir/ie-class.rb', line 518 def document return @ie.document end |
#document_mode ⇒ Object
The document standards mode used by IE can be overridden in the html with: <meta http-equiv=“x-ua-compatible” content=“IE=8”>
373 374 375 |
# File 'lib/watir/ie-class.rb', line 373 def document_mode @ie.document.documentMode.to_i end |
#element_by_css(selector) ⇒ Object
return the first (ole object) element that matches the css selector
967 968 969 970 |
# File 'lib/watir/ie-class.rb', line 967 def element_by_css(selector) temp = elements_by_css(selector) return temp[0] if temp end |
#element_by_xpath(xpath) ⇒ Object
return the first element that matches the xpath
973 974 975 976 977 |
# File 'lib/watir/ie-class.rb', line 973 def element_by_xpath(xpath) temp = elements_by_xpath(xpath) temp = temp[0] if temp return temp end |
#elements_by_css(selector) ⇒ Object
execute css selector and return an array of (ole object) elements
960 961 962 963 964 |
# File 'lib/watir/ie-class.rb', line 960 def elements_by_css(selector) xmlparser_document_object # Needed to ensure Nokogiri has been loaded xpath = Nokogiri::CSS.xpath_for(selector)[0] elements_by_xpath(xpath) end |
#elements_by_xpath(xpath) ⇒ Object
execute xpath and return an array of elements
980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 |
# File 'lib/watir/ie-class.rb', line 980 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
421 422 423 424 425 426 427 428 429 430 431 432 433 |
# File 'lib/watir/ie-class.rb', line 421 def execute_script(source) document.parentWindow.eval(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 |
#exists? ⇒ Boolean Also known as: exist?
Are we attached to an open browser?
344 345 346 347 348 349 350 |
# File 'lib/watir/ie-class.rb', line 344 def exists? begin !!(@ie.name =~ /Internet Explorer/) rescue WIN32OLERuntimeError, NoMethodError false end end |
#focus ⇒ Object
Gives focus to the frame
753 754 755 756 |
# File 'lib/watir/ie-class.rb', line 753 def focus document.activeElement.blur document.focus end |
#forward ⇒ Object
Go to the next page - the same as clicking the browsers forward button an WIN32OLERuntimeError exception is raised if the browser cant go forward
404 405 406 407 |
# File 'lib/watir/ie-class.rb', line 404 def forward @ie.GoForward wait end |
#getIE ⇒ Object
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
389 390 391 392 393 |
# File 'lib/watir/ie-class.rb', line 389 def goto(url) @ie.navigate(url) wait return @down_load_time end |
#initialize_options ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 |
# File 'lib/watir/ie-class.rb', line 182 def 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 |
#inspect ⇒ Object
416 417 418 |
# File 'lib/watir/ie-class.rb', line 416 def inspect '#<%s:0x%x url=%s title=%s>' % [self.class, hash*2, url.inspect, title.inspect] end |
#kill ⇒ Object
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
358 359 360 |
# File 'lib/watir/ie-class.rb', line 358 def log(what) @logger.debug(what) if @logger end |
#maximize ⇒ Object
Maximize the window (expands to fill the screen)
457 458 459 |
# File 'lib/watir/ie-class.rb', line 457 def maximize rautomation.maximize end |
#minimize ⇒ Object
Minimize the window (appears as icon on taskbar)
462 463 464 |
# File 'lib/watir/ie-class.rb', line 462 def minimize rautomation.minimize end |
#minimized? ⇒ Boolean
466 467 468 |
# File 'lib/watir/ie-class.rb', line 466 def minimized? rautomation.minimized? end |
#rautomation ⇒ Object
486 487 488 489 |
# File 'lib/watir/ie-class.rb', line 486 def rautomation @rautomation ||= ::RAutomation::Window.new(:hwnd => hwnd) @rautomation end |
#refresh ⇒ Object
Refresh the current page - the same as clicking the browsers refresh button an WIN32OLERuntimeError exception is raised if the browser cant refresh
411 412 413 414 |
# File 'lib/watir/ie-class.rb', line 411 def refresh @ie.refresh2(3) wait end |
#restore ⇒ Object
Restore the window (after minimizing or maximizing)
471 472 473 |
# File 'lib/watir/ie-class.rb', line 471 def restore rautomation.restore end |
#run_error_checks ⇒ Object
this method runs the predefined error checks
589 590 591 |
# File 'lib/watir/ie-class.rb', line 589 def run_error_checks @error_checkers.each { |e| e.call(self) } end |
#send_keys(key_string) ⇒ Object
Activates the window and sends keys to it.
Example:
browser.send_keys("Hello World{enter}")
Refer to RAutomation::Adapter::WinFfi::KeystrokeConverter.convert_special_characters for special characters conversion.
505 506 507 |
# File 'lib/watir/ie-class.rb', line 505 def send_keys(key_string) rautomation.send_keys key_string end |
#set_fast_speed ⇒ Object
deprecated: use speed = :fast instead
230 231 232 |
# File 'lib/watir/ie-class.rb', line 230 def set_fast_speed self.speed = :fast end |
#set_logger(logger) ⇒ Object
deprecated: use logger= instead
354 355 356 |
# File 'lib/watir/ie-class.rb', line 354 def set_logger(logger) @logger = logger end |
#set_slow_speed ⇒ Object
deprecated: use speed = :slow instead
235 236 237 |
# File 'lib/watir/ie-class.rb', line 235 def set_slow_speed self.speed = :slow end |
#show_active ⇒ Object 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
679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
# File 'lib/watir/ie-class.rb', line 679 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_divs ⇒ Object
this method shows all the divs availble in the document
700 701 702 703 704 705 706 707 708 |
# File 'lib/watir/ie-class.rb', line 700 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_forms ⇒ Object Also known as: showForms
Show all forms displays all the forms that are on a web page.
610 611 612 613 614 615 616 617 618 619 620 621 622 623 |
# File 'lib/watir/ie-class.rb', line 610 def show_forms if all_forms = self.forms count = all_forms.length puts "There are #{count} forms" all_forms.each do |form| puts "Form name: #{form.name}" puts " id: #{form.id}" puts " method: #{form.method}" puts " action: #{form.action}" end else puts "No forms" end end |
#show_images ⇒ Object Also known as: showImages
this method shows all the images availble in the document
626 627 628 629 630 631 632 633 634 635 636 |
# File 'lib/watir/ie-class.rb', line 626 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_labels ⇒ Object
742 743 744 745 746 747 748 749 750 |
# File 'lib/watir/ie-class.rb', line 742 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 |
#show_links ⇒ Object Also known as: showLinks
this method shows all the links availble in the document
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 |
# File 'lib/watir/ie-class.rb', line 639 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_pres ⇒ Object
721 722 723 724 725 726 727 728 729 |
# File 'lib/watir/ie-class.rb', line 721 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_spans ⇒ Object
this method shows all the spans availble in the document
732 733 734 735 736 737 738 739 740 |
# File 'lib/watir/ie-class.rb', line 732 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_tables ⇒ Object
this method is used to show all the tables that are available
711 712 713 714 715 716 717 718 719 |
# File 'lib/watir/ie-class.rb', line 711 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 |
#speed ⇒ Object
224 225 226 227 |
# File 'lib/watir/ie-class.rb', line 224 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).
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/watir/ie-class.rb', line 202 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 |
#status ⇒ Object Also known as: getStatus
Return the status of the window, typically from the status bar at the bottom.
379 380 381 |
# File 'lib/watir/ie-class.rb', line 379 def status return @ie.statusText end |
#title ⇒ Object
Return the title of the document
367 368 369 |
# File 'lib/watir/ie-class.rb', line 367 def title @ie.document.title end |
#url ⇒ Object
returns the current url, as displayed in the address bar of the browser
523 524 525 |
# File 'lib/watir/ie-class.rb', line 523 def url return @ie.LocationURL end |
#visible ⇒ Object
239 240 241 |
# File 'lib/watir/ie-class.rb', line 239 def visible @ie.visible end |
#visible=(boolean) ⇒ Object
242 243 244 |
# File 'lib/watir/ie-class.rb', line 242 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!
537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/watir/ie-class.rb', line 537 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 READYSTATES.has_value?(@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 READYSTATES.has_key?(doc.readyState.to_sym) 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_object ⇒ Object
Functions written for using xpath for getting the elements.
760 761 762 763 764 765 |
# File 'lib/watir/ie-class.rb', line 760 def xmlparser_document_object if @xml_parser_doc == nil create_xml_parser_doc end return @xml_parser_doc end |